Skip to content

test(coverage): scheduler + embed + generate tests; enforce coverage in CI#60

Merged
LanNguyenSi merged 2 commits into
masterfrom
test/agent-memory-coverage
Jun 30, 2026
Merged

test(coverage): scheduler + embed + generate tests; enforce coverage in CI#60
LanNguyenSi merged 2 commits into
masterfrom
test/agent-memory-coverage

Conversation

@LanNguyenSi

Copy link
Copy Markdown
Owner

Closes the 4 agent-memory test-coverage audit gaps (2 MED + 2 LOW). Toolchain is node:test (node --test) with tsx.

  • M1 agent-memory-sync cron scheduler (28 tests): parseCron (wildcard/step/range/list + 10 invalid-expr throws) and nextScheduleTick (step/range/list, hour + day-of-week boundaries, month + year-end rollover, the 525600-iteration cap), with exact next-run timestamp assertions.
  • M2 memory-router embed/provider.ts (11 tests): stub global fetch for embedBatch (ok -> exact URL/method/headers/body + sorted vectors; non-ok 429/500 -> throws; network + AbortError propagation; body-read fallback) and resolveProviderConfig (missing key -> null, default/custom model, custom baseUrl).
  • L2 memory-digest-cli generate command (8 tests): registerGenerateCommand option parsing (defaults, overrides, boolean flags, short aliases).
  • L1 CI coverage enforcement: each package's test:coverage now passes node:test native --test-coverage-{lines,branches,functions} thresholds (src only via --test-coverage-exclude), and the CI step runs test:coverage so coverage regressions fail the build. Calibrated below measured, negative-control verified.

Two real CI gaps fixed while wiring coverage

  • memory-router test glob was unquoted (tests/**/*.test.ts), so the shell expanded it to one-level subdirs and the 19 top-level tests/*.test.ts files never ran in CI. Quoting it lets Node's native glob run the full suite: 43 -> 231 tests now execute.
  • agent-memory-sync scheduler test now loads src/ under tsx instead of compiled dist/, so coverage measures source and the suite no longer silently depends on a prior build (the package had no pretest:build).

Adversarial verify

Reviewer ran 9 prod-source mutations (all killed; no inert tests in the mutated paths) and confirmed both CI fixes. It flagged that memory-router's coverage number was double-counting dist/ (real-corpus.test.ts loads compiled output) — folded --test-coverage-exclude='dist/**', which revealed true src coverage is 96/86/86 and let me recalibrate the thresholds up to 90/80/80, plus added pretest:coverage for local dev. A pre-existing scheduler step=0 infinite-loop (validateCronExpression('*/0 * * * *') hangs) and the generate.ts action-body coverage are tracked in a MEDIUM follow-up (out of scope for a test PR).

Refs: tc-audit-2026-06-27

…rce coverage in CI

Closes the 4 agent-memory audit gaps (2 MED + 2 LOW). Toolchain is node:test.

M1 agent-memory-sync cron scheduler: 28 tests for parseCron (wildcard/step/
range/list + 10 invalid-expr throws) and nextScheduleTick (step/range/list,
hour+day-of-week boundaries, month + year-end rollover, the 525600-iteration
cap), with exact-timestamp value assertions.

M2 memory-router embed/provider.ts: 11 tests stubbing global fetch for
embedBatch (ok -> exact URL/method/headers/body + sorted vectors; non-ok
429/500 -> throws; network + AbortError propagation; body-read fallback) and
resolveProviderConfig (missing key -> null, default/custom model, custom baseUrl).

L2 memory-digest-cli generate command: 8 tests for registerGenerateCommand
option parsing (6 defaults, overrides, boolean flags, short aliases).

L1 CI coverage enforcement: each package's test:coverage now passes
--test-coverage-{lines,branches,functions} thresholds (node:test native, src
only via --test-coverage-exclude); the CI step runs test:coverage so the gate
is enforced. Calibrated below measured, negative-control verified.

Also fixes two real CI gaps surfaced while wiring coverage:
- memory-router `test` glob `tests/**/*.test.ts` was unquoted, so the shell
  expanded it to one-level subdirs and the 19 top-level tests/*.test.ts files
  (tool, query-cache, ...) never ran in CI. Quoting it lets Node's native
  glob run the full suite: 43 -> 231 tests now execute.
- agent-memory-sync scheduler test now loads src (under tsx) instead of dist,
  so coverage measures source and the suite no longer depends on a prior build
  (the package had no pretest:build). Switched the package to node --import tsx.

Refs: tc-audit-2026-06-27
…coverage

Adversarial review (9/9 prod mutations killed) flagged that memory-router's
coverage number double-counted dist + src: tests/coverage/real-corpus.test.ts
loads ../../dist/*, and --test-coverage-exclude only dropped tests/**, so
low-coverage compiled modules (drift.js 13%, applier.js 8%, ...) polluted the
figure (65.28) the thresholds were calibrated against.

- Add --test-coverage-exclude='dist/**' so the gate measures source only;
  true src coverage is 96.10/85.80/85.84, so recalibrated the thresholds to
  90/80/80 (was 60/73/62, far too low). Negative-control verified.
- Add pretest:coverage=npm run build so `npm run test:coverage` works on a
  fresh local checkout (real-corpus.test.ts requires dist; CI already had an
  explicit Build step so CI was unaffected).

Pre-existing scheduler step=0 infinite-loop and the generate.ts action-body
coverage are tracked in a follow-up (out of scope for this test PR).

Refs: tc-audit-2026-06-27
@LanNguyenSi LanNguyenSi merged commit 80d6072 into master Jun 30, 2026
3 of 5 checks passed
@LanNguyenSi LanNguyenSi deleted the test/agent-memory-coverage branch June 30, 2026 08:29
@LanNguyenSi LanNguyenSi added review:tests-pass merge-approval gate prerequisite review:checklist-complete merge-approval gate prerequisite review:comments-resolved merge-approval gate prerequisite review:scope-matches-task merge-approval gate prerequisite review:evidence-logged merge-approval gate prerequisite labels Jun 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

review:checklist-complete merge-approval gate prerequisite review:comments-resolved merge-approval gate prerequisite review:evidence-logged merge-approval gate prerequisite review:scope-matches-task merge-approval gate prerequisite review:tests-pass merge-approval gate prerequisite

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants