Skip to content

fix: add offline advisory db sync hint#407

Open
MFA-G wants to merge 1 commit into
OWASP:mainfrom
MFA-G:fix/offline-db-sync-hint
Open

fix: add offline advisory db sync hint#407
MFA-G wants to merge 1 commit into
OWASP:mainfrom
MFA-G:fix/offline-db-sync-hint

Conversation

@MFA-G
Copy link
Copy Markdown

@MFA-G MFA-G commented May 23, 2026

Summary

  • add actionable cve-lite advisories sync guidance when offline advisory DB initialization fails
  • include --output <path> guidance when users pass a custom --offline-db path
  • cover both default offline mode and custom DB path failures in CLI integration tests

Fixes #402

Verification

  • npm test -- --runInBand tests/cli-integration.test.ts
  • npm run build

Comment thread src/index.ts
const syncHint = options.offlineDb
? `To build it, run: cve-lite advisories sync\nOr to save it to the requested path: cve-lite advisories sync --output ${options.offlineDb}`
: "To build it, run: cve-lite advisories sync";
throw new Error(`Offline advisory database is not available: ${reason}\n${syncHint}`);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The string "To build it, run: cve-lite advisories sync" appears in both branches — it's the full else value and also the opening line of the if branch. If the command ever changes, it needs updating in two places. Worth extracting to a constant:

const BASE_SYNC_HINT = "To build it, run: cve-lite advisories sync";
const syncHint = options.offlineDb
  ? `${BASE_SYNC_HINT}\nOr to save it to the requested path: cve-lite advisories sync --output ${options.offlineDb}`
  : BASE_SYNC_HINT;

parseArgsMock.mockReturnValue({
command: "scan",
options: {
offline: true,
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The four options failOn, batchSize, searchDepth, minSeverity are identical across both tests. A shared object at the top of the block makes it obvious which option is actually under test in each case:

const BASE_SCAN_OPTIONS = {
  failOn: "critical",
  batchSize: "100",
  searchDepth: "4",
  minSeverity: "medium",
} as const;

// then per test:
options: { offline: true, ...BASE_SCAN_OPTIONS }
options: { offlineDb: "/tmp/custom-advisories.db", ...BASE_SCAN_OPTIONS }


expect(result.exitCode).toBe(1);
expect(stripAnsi(result.stderr.join("\n"))).toContain("Offline advisory database is not available: file does not exist");
expect(stripAnsi(result.stderr.join("\n"))).toContain("To build it, run: cve-lite advisories sync");
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

stripAnsi(result.stderr.join("\n")) is evaluated twice here (and again in the second test). Store it once so the assertions read more cleanly:

const stderr = stripAnsi(result.stderr.join("\n"));
expect(stderr).toContain("Offline advisory database is not available: file does not exist");
expect(stderr).toContain("To build it, run: cve-lite advisories sync");

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: offline advisory DB unavailable error should include the sync command to create it

2 participants