Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 13 additions & 3 deletions tests/dailyRefinement.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {}

Copy link
Copy Markdown
Contributor

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 unlinkSync can hide real problems. If the file exists but removal fails for a reason other than ENOENT (e.g., permission denied, file locked), the test will proceed with a stale database and may produce misleading results. Consider re-throwing non-ENOENT errors:

try { fs.unlinkSync(dbPath); } catch (e: any) {
  if (e.code !== 'ENOENT') throw e;
}

The same applies to the afterAll cleanup block.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At tests/dailyRefinement.test.ts, line 18:

<comment>Silently catching all exceptions from `unlinkSync` can hide real problems. If the file exists but removal fails for a reason other than `ENOENT` (e.g., permission denied, file locked), the test will proceed with a stale database and may produce misleading results. Consider re-throwing non-`ENOENT` errors:

```ts
try { fs.unlinkSync(dbPath); } catch (e: any) {
  if (e.code !== 'ENOENT') throw e;
}

The same applies to the afterAll cleanup block.

@@ -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); ```

}
Comment on lines +17 to +19

Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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 || true

Repository: 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 test_issues.db behind while the test suite still reports success:

  • beforeAll: fail setup on any unlinkSync error except ENOENT instead of proceeding with a corrupted/stale database.
  • afterAll: close the TrendAnalyzer callback-backed database before unlinking and propagate non-ENOENT cleanup errors instead of relying on a 500ms timer.
📍 Affects 1 file
  • tests/dailyRefinement.test.ts#L17-L19 (this comment)
  • tests/dailyRefinement.test.ts#L37-L43
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/dailyRefinement.test.ts` around lines 17 - 19, Update both database
cleanup sites in tests/dailyRefinement.test.ts: in beforeAll, let unlinkSync
failures propagate unless the error code is ENOENT; in afterAll, explicitly
close the TrendAnalyzer callback-backed database before unlinking, remove the
500ms timer workaround, and propagate any non-ENOENT unlinkSync failure.

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)');
Expand All @@ -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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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; }
done

Repository: 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 || true

Repository: RohanExploit/VishwaGuru

Length of output: 11639


🌐 Web query:

node-sqlite3 v6 Database.prototype run Statement.prototype run finalize close callback error signature

💡 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.

db.run and stmt.run callback on errors, but these calls omit callbacks so table creation or inserts can fail without calling beforeAll’s done; only db.close(done) reports the close operation. Add callbacks for these setup operations that pass the first error to done, and only close when the seeding pipeline succeeds.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/dailyRefinement.test.ts` around lines 31 - 33, Update the beforeAll
fixture-seeding flow in tests/dailyRefinement.test.ts, including the db.run and
stmt.run operations around stmt.finalize, to propagate each operation’s first
error to Jest’s done callback and stop the pipeline on failure. Only invoke
db.close(done) after table creation and inserts complete successfully,
preserving the existing successful cleanup behavior.

Source: MCP tools

Comment on lines +31 to +33

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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
Check if this issue is valid — if so, understand the root cause and fix it. At tests/dailyRefinement.test.ts, line 31:

<comment>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.</comment>

<file context>
@@ -25,12 +28,19 @@ describe('Daily Civic Intelligence Refinement Engine', () => {
         stmt.run('Another pothole here', 'infrastructure', 'Ward 1', now);
 
-        stmt.finalize(done);
+        stmt.finalize(() => {
+          db.close(done);
+        });
</file context>
Suggested change
stmt.finalize(() => {
db.close(done);
});
stmt.finalize((err) => {
if (err) return done(err);
db.close(done);
});

});
});

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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
Check if this issue is valid — if so, understand the root cause and fix it. At tests/dailyRefinement.test.ts, line 43:

<comment>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.</comment>

<file context>
@@ -25,12 +28,19 @@ describe('Daily Civic Intelligence Refinement Engine', () => {
+          try { fs.unlinkSync(dbPath); } catch (e) {}
+        }
+        done();
+      }, 500); // wait for locks to release
     });
 
</file context>

});

it('should correctly analyze trends in the last 24 hours', async () => {
Expand Down
Loading