qmd/test
Riley Shott aa1818e181
fix: clamp negative fromLine in get to avoid silent tail content
The query tool description tells agents to compute fromLine = line - 20
for context around a hit. For hits in lines 1 through 20 that yields a
negative fromLine, which propagated unchanged through:

  MCP get handler -> store.getDocumentBody -> Array.prototype.slice

A negative slice start offsets from the end of the array rather than
clamping to the beginning, so a top-of-file hit on a long document
returned an empty string and on a short document returned content from
the wrong region (e.g. lines 11-30 of a 30-line file in response to a
request for the head of the document). The lineNumbers branch was the
same shape: addLineNumbers(text, -19) emitted "-19:", "-18:" prefixes.

Same buggy slice lived in the CLI getDocument path independently.

Fix in three layers, plus the docstring:

- src/mcp/server.ts: clamp parsedFromLine to >= 1 after parsing input
  args and the :line suffix, before it reaches getDocumentBody and
  addLineNumbers. Also tighten the query tool's recommendation to
  `fromLine = max(1, line - 20)` so following the docstring literally
  produces a valid value.
- src/cli/qmd.ts: same clamp on the CLI getDocument fromLine after
  the colon-suffix parse.
- src/store.ts: defensive Math.max(0, ...) on the slice start in
  getDocumentBody so SDK callers and any future entry points are
  protected without relying on every caller remembering to clamp.
- test/store.test.ts: regression test on getDocumentBody with
  fromLine = -19 returns the head of the document, not the tail.
- test/cli.test.ts: regression test on `qmd get --from -19` matches
  the no-flag baseline (head of document).
2026-05-13 23:59:33 -07:00
..
eval-docs Add 6 synthetic evaluation documents 2025-12-21 13:10:35 -04:00
ast-chunking.test.ts chore: migrate AST chunking tests to vitest 2026-04-05 17:19:59 -04:00
ast.test.ts Fix AST grammar packaging for Bun installs 2026-05-09 18:13:58 +00:00
bench-score.test.ts feat(cli): add qmd bench command for search quality benchmarks 2026-04-05 17:17:59 -04:00
cli-lazy-llm-import.test.ts fix(cli): keep status from importing llama 2026-05-09 18:12:45 +00:00
cli.test.ts fix: clamp negative fromLine in get to avoid silent tail content 2026-05-13 23:59:33 -07:00
collections-config.test.ts fix embed model and qmd home resolution 2026-05-09 18:17:10 +00:00
Containerfile test: restructure container smoke tests for interactive use 2026-02-22 11:09:36 -04:00
esm-ambiguous-module.test.ts test: make CI fixture invocations portable 2026-05-09 18:45:56 +00:00
eval-bm25.test.ts test: move all tests to flat test/ directory 2026-02-15 21:37:47 -04:00
eval-deep-research.jsonl Merge origin/main into feat/ast-aware-chunking 2026-03-28 20:00:49 -04:00
eval-deep-research.ts Merge origin/main into feat/ast-aware-chunking 2026-03-28 20:00:49 -04:00
eval-harness.ts refactor: move CLI and MCP to subdirectories, MCP consumes SDK 2026-03-10 11:39:55 -04:00
eval.test.ts test: move all tests to flat test/ directory 2026-02-15 21:37:47 -04:00
formatter.test.ts Add line to JSON search output 2026-04-05 10:08:57 +00:00
intent.test.ts refactor: move CLI and MCP to subdirectories, MCP consumes SDK 2026-03-10 11:39:55 -04:00
launcher-detection.test.sh fix: prioritize package-lock.json in launcher to prevent Bun false positive 2026-03-12 01:46:38 -07:00
llm.test.ts test: allow slow CPU rerank fixture 2026-05-09 18:20:26 +00:00
mcp.test.ts fix: return absolute line numbers from qmd_query 2026-05-13 23:59:32 -07:00
multi-collection-filter.test.ts refactor: replace bash wrapper with standard #!/usr/bin/env node shebang 2026-02-22 11:09:36 -04:00
package.test.ts Fix AST grammar packaging for Bun installs 2026-05-09 18:13:58 +00:00
rrf-trace.test.ts feat(query): add --explain score traces for hybrid search 2026-03-07 14:35:10 -04:00
sdk.test.ts fix(embed): honor collection filter 2026-05-09 18:12:45 +00:00
smoke-install.sh test: restructure container smoke tests for interactive use 2026-02-22 11:09:36 -04:00
store-paths.test.ts test: move all tests to flat test/ directory 2026-02-15 21:37:47 -04:00
store.helpers.unit.test.ts fix: preserve original case in handelize() 2026-04-09 07:59:22 +09:00
store.test.ts fix: clamp negative fromLine in get to avoid silent tail content 2026-05-13 23:59:33 -07:00
structured-search.test.ts Merge pull request #384 from rymalia/fix/semantic-query-hyphen-validation 2026-05-02 20:16:30 -04:00