-
Notifications
You must be signed in to change notification settings - Fork 41
[FEATURE] Add unit tests for core functionality #934
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -14,6 +14,9 @@ describe('Daily Civic Intelligence Refinement Engine', () => { | |||||||||||||||
|
|
||||||||||||||||
| beforeAll((done) => { | ||||||||||||||||
| dbPath = path.resolve(__dirname, 'test_issues.db'); | ||||||||||||||||
| if (fs.existsSync(dbPath)) { | ||||||||||||||||
| try { fs.unlinkSync(dbPath); } catch (e) {} | ||||||||||||||||
| } | ||||||||||||||||
|
Comment on lines
+17
to
+19
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🩺 Stability & Availability | 🟠 Major | ⚡ Quick win 🧩 Analysis chain🏁 Script executed: #!/bin/bash
set -euo pipefail
echo "== files =="
git ls-files | rg '(^|/)dailyRefinement\.test\.ts$|dailyRefinement|issues\.db|test_issues\.db' || true
echo "== target file outline/size =="
if [ -f tests/dailyRefinement.test.ts ]; then
wc -l tests/dailyRefinement.test.ts
ast-grep outline tests/dailyRefinement.test.ts --view compact || true
echo "== target file relevant sections =="
sed -n '1,90p' tests/dailyRefinement.test.ts | cat -n
fi
echo "== SQLite/database references in tests =="
rg -n "test_issues\.db|createClient|close|unlinkSync|existsSync|dbPath|sqlite|SQLite|dailyRefinement" tests src . 2>/dev/null | head -200 || trueRepository: RohanExploit/VishwaGuru Length of output: 16083 🏁 Script executed: #!/bin/bash
set -euo pipefail
echo "== trendAnalyzer outline =="
ast-grep outline services/trendAnalyzer.ts --view signatures || true
echo "== trendAnalyzer relevant sections =="
sed -n '1,110p' services/trendAnalyzer.ts | cat -n
echo "== package test scripts =="
cat package.json | jq '{scripts: .scripts, dependencies: {sqlite3:.dependencies.sqlite3}, devDependencies:.devDependencies}'Repository: RohanExploit/VishwaGuru Length of output: 3607 Do not silently ignore SQLite cleanup failures. Both lifecycle boundaries can leave
📍 Affects 1 file
🤖 Prompt for AI Agents |
||||||||||||||||
| const db = new sqlite3.Database(dbPath); | ||||||||||||||||
| db.serialize(() => { | ||||||||||||||||
| db.run('CREATE TABLE issues (id INTEGER PRIMARY KEY, description TEXT, category TEXT, location TEXT, created_at DATETIME)'); | ||||||||||||||||
|
|
@@ -25,12 +28,19 @@ describe('Daily Civic Intelligence Refinement Engine', () => { | |||||||||||||||
| stmt.run('Water supply is completely broken', 'water', 'Ward 2', now); | ||||||||||||||||
| stmt.run('Another pothole here', 'infrastructure', 'Ward 1', now); | ||||||||||||||||
|
|
||||||||||||||||
| stmt.finalize(done); | ||||||||||||||||
| stmt.finalize(() => { | ||||||||||||||||
| db.close(done); | ||||||||||||||||
| }); | ||||||||||||||||
|
Comment on lines
+31
to
+33
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🩺 Stability & Availability | 🟠 Major | ⚡ Quick win 🧩 Analysis chain🏁 Script executed: #!/bin/bash
set -euo pipefail
echo "== locate file =="
fd -a dailyRefinement.test.ts . || true
echo "== inspect file around relevant lines =="
if [ -f tests/dailyRefinement.test.ts ]; then
cat -n tests/dailyRefinement.test.ts | sed -n '1,120p'
fi
echo "== package hints for sqlite dependency =="
for f in package.json pnpm-lock.yaml package-lock.json yarn.lock; do
[ -f "$f" ] && { echo "--- $f"; rg -n "sqlite3|better-sqlite3|node-sqlite3" "$f" || true; }
doneRepository: RohanExploit/VishwaGuru Length of output: 5816 🏁 Script executed: #!/bin/bash
set -euo pipefail
# Inspect whether node-sqlite3's API signature for CREATE TABLE/run/close/use callbacks is present in the repository
# as installed docs or examples, and compare common callback behavior from local package metadata/docs if present.
python3 - <<'PY'
from pathlib import Path
paths=[]
for root in [Path('.')]:
for p in root.rglob('*sqlite3*'):
if p.is_file():
paths.append(str(p))
print("sqlite3-related files:", "\n".join(paths[:20]) if paths else "(none)")
for p in [Path('node_modules/sqlite3/package.json'), Path('node_modules/sqlite3/LICENSE.md'), Path('node_modules/better-sqlite3/package.json')]:
if p.exists():
print(f"--- {p} first 20 lines")
lines=p.read_text(encoding='utf-8', errors='replace').splitlines()[:20]
print("\n".join(lines))
PY
echo "== any local documentation examples =="
rg -n "stmt\\.run|CREATE TABLE|db\\.close|db\\.serialize|node-sqlite3|better-sqlite3" . \
-g '!node_modules' -g '!dist' -g '!build' -g '!coverage' \
-C 3 || trueRepository: RohanExploit/VishwaGuru Length of output: 11639 🌐 Web query:
💡 Result: In the node-sqlite3 library, the callback error signature for Database#run, Statement#run, Database#close, and Statement#finalize generally follows the standard Node.js convention where the first argument is an error object (or null if no error occurred) [1][2][3]. Specifically, the callback signatures are as follows: Database.prototype.run and Statement.prototype.run The callback signature is function(err). If an error occurs, the first parameter is an Error object; if execution is successful, the first parameter is null [1][2]. Note that unlike some other Node.js libraries, result data for run is not passed as an argument to the callback; instead, relevant information (such as changes or lastID) is accessed via the 'this' context of the callback function [1][4]. Because of this binding, you should avoid using arrow functions for these callbacks if you need to access that context, as arrow functions lexically bind 'this' [5][4]. Database.prototype.close The callback signature is function(err). The err parameter will be an Error object if the database fails to close, or null if it closes successfully [2][6]. Statement.prototype.finalize The callback signature is function(err). Similar to the others, the first parameter is an Error object if an error occurs during finalization, or null otherwise [2]. Summary of callback error behavior: - If a callback is provided, errors are passed as the first argument [1][3]. - If no callback is provided, errors are typically emitted as 'error' events on the database or statement object [1][7][3]. - For run specifically, remember that data is returned via the 'this' object, not as a second argument to the callback [1][4]. Citations:
Propagate fixture-seeding errors into Jest.
🤖 Prompt for AI AgentsSource: MCP tools
Comment on lines
+31
to
+33
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: Database setup can report success even when statement finalization fails, leaving incomplete seed data and making the test pass or fail for the wrong reason. Preserving the finalize error before closing the database keeps setup failures visible. Prompt for AI agents
Suggested change
|
||||||||||||||||
| }); | ||||||||||||||||
| }); | ||||||||||||||||
|
|
||||||||||||||||
| afterAll(() => { | ||||||||||||||||
| if (fs.existsSync(dbPath)) fs.unlinkSync(dbPath); | ||||||||||||||||
| afterAll((done) => { | ||||||||||||||||
| setTimeout(() => { | ||||||||||||||||
| if (fs.existsSync(dbPath)) { | ||||||||||||||||
| try { fs.unlinkSync(dbPath); } catch (e) {} | ||||||||||||||||
| } | ||||||||||||||||
| done(); | ||||||||||||||||
| }, 500); // wait for locks to release | ||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: Teardown is still racy: a fixed delay does not prove that SQLite released the lock, and cleanup failure can be hidden after the delay. Awaiting the analyzer/database close completion and reporting or retrying unlink errors would prevent leaked test artifacts and cross-run contamination. Prompt for AI agents |
||||||||||||||||
| }); | ||||||||||||||||
|
|
||||||||||||||||
| it('should correctly analyze trends in the last 24 hours', async () => { | ||||||||||||||||
|
|
||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P2: Silently catching all exceptions from
unlinkSynccan hide real problems. If the file exists but removal fails for a reason other thanENOENT(e.g., permission denied, file locked), the test will proceed with a stale database and may produce misleading results. Consider re-throwing non-ENOENTerrors:The same applies to the
afterAllcleanup block.Prompt for AI agents
The same applies to the
@@ -14,6 +14,9 @@ describe('Daily Civic Intelligence Refinement Engine', () => { beforeAll((done) => { dbPath = path.resolve(__dirname, 'test_issues.db'); + if (fs.existsSync(dbPath)) { + try { fs.unlinkSync(dbPath); } catch (e) {} + } const db = new sqlite3.Database(dbPath); ```afterAllcleanup block.