Skip to content

fix: docs delete input validation, and same-second document list order - #529

Merged
RobertLD merged 2 commits into
mainfrom
fix/docs-delete-get-document
Oct 9, 2026
Merged

RobertLD merged 2 commits into
mainfrom
fix/docs-delete-get-document

Conversation

@RobertLD

@RobertLD RobertLD commented Oct 9, 2026 •

Copy link
Copy Markdown
Owner

1. docs delete always failed

libscope docs delete <id> fails in 2.0.1:

✗ Invalid input for get-document: maxLength: Too small: expected number to be >0

To show the title in the confirmation, the command calls get-document with maxLength: 0 (src/cli/commands/docs.ts:173). get-document requires maxLength to be a positive integer, so the lookup fails before anything is deleted.

Fix: call get-document without maxLength. getDocumentView reads the full content either way and only slices it, so this costs nothing.

Tests: the CLI contract test replaces runOperation with a spy, so inputs were never validated, and it asserted maxLength: 0 (the failing input) as the expected call. The expectation now matches the fix, and invoke() checks every operation call's input against the operation's own schema. Without the code fix, the docs delete test fails with get-document input: … "maxLength". All 94 CLI contract tests pass the new check, so no other command sends invalid input.

2. Document list order within the same second

listDocuments sorted only by updated_at, which has one-second resolution. Documents updated in the same second came back oldest first, in an order that depended on timing. That made lite.test.ts "gives the same results as LibScope.create" flaky: it failed on Node 20 in this PR's first CI run (received Vue, Angular, React; expected React, Vue, Angular), consistent with one database's inserts crossing a second boundary and the other's not. I inferred that cause from the failure; I did not reproduce the timing.

Fix: ORDER BY d.updated_at DESC, d.rowid DESC, newest insert first on ties.

Tests: one new test in documents.test.ts sets the same updated_at on every document and expects newest insert first. It fails without the fix. lite.test.ts is unchanged.

Verification

  • Built CLI against a throwaway database: add a file, then docs delete <id> --yes prints ✓ Deleted "delete-me" (…), exit 0, and no documents remain.
  • npm run lint (0 errors), format:check, typecheck, test:coverage: 2139 tests pass.

`libscope docs delete <id>` looked the document up with
`get-document {maxLength: 0}` to show its title, but get-document
requires a positive maxLength, so every delete failed with
"Invalid input for get-document: maxLength: Too small". Look the
document up without maxLength; getDocumentView reads the whole
content either way.

The CLI contract tests replace runOperation with a spy, so inputs were
never validated and the test asserted maxLength: 0. invoke() now checks
each call's input against the operation's schema.
@vercel

vercel Bot commented Oct 9, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated
libscope Ignored Ignored Preview Oct 9, 2026 8:37pm UTC

listDocuments sorted only by updated_at, which has one-second
resolution, so documents updated in the same second came back oldest
first and in an order that depended on timing. That made the lite test
"gives the same results as LibScope.create" flaky on Node 20: when one
database's inserts crossed a second boundary and the other's did not,
the two lists differed. Break ties by rowid, newest insert first.
@RobertLD RobertLD changed the title fix: docs delete no longer fails input validation fix: docs delete input validation, and same-second document list order Oct 9, 2026
@sonarqubecloud

sonarqubecloud Bot commented Oct 9, 2026

Copy link
Copy Markdown

@RobertLD
RobertLD merged commit bae6bef into main Oct 9, 2026
10 checks passed
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.

1 participant