Skip to content

fix(store): name an unreadable record instead of calling the package invalid - #254

Merged
Antruly merged 1 commit into
mainfrom
fix/253-template-store-metadata-read
Oct 18, 2026
Merged

Antruly merged 1 commit into
mainfrom
fix/253-template-store-metadata-read

Conversation

@Antruly

@Antruly Antruly commented Oct 18, 2026 •

Copy link
Copy Markdown
Owner

Summary

Fixes #253. readStoreMetadata caught every failure and returned "no record", so a store record that existed but could not be read (EACCES, EISDIR, EIO) was treated as absent. For a package imported with allowUnverified, that flipped the Q6 flag back to false and the store reported the package as invalid — a claim about manifest bytes that were never judged.

The reader now answers three ways — read, absent, unreadable. Absence stays an observation the callers act on (a strict package needs none; an unverified package without one fails closed). An unreadable record only changes the answer when the package's own validation failed solely on licence/provenance, which is the case the record decides; there the store reports io_error naming the record. Any genuine package problem (a digest mismatch, an oversized file) is reported as before.

Problem and expected behavior

Observed on main at ffa8350 (Linux, uid 1000):

  1. Import a package with allowUnverified: true and no license/provenance.
  2. chmod 000 <root>/.meta/acme-dashboard/1.2.0.json.
  3. getTemplatePackage → invalid_package — "the package does not match uvp.template/1"; listTemplatePackages → 0 packages, corrupt problems license: is required, provenance: is required.

The underlying failure is EACCES: permission denied, open '<root>/.meta/acme-dashboard/1.2.0.json'. The package bytes were never the problem. Expected: name the record that could not be read, per the third-state rule in AGENTS.md; do not convert "could not look" into "the package is a no".

Change and scope

  • readStoreMetadata returns read | absent | unreadable instead of StoreMetadata | undefined; only ENOENT maps to absent.
  • recordFailureOf maps an unreadable record to io_error only when every validation problem is a licence/provenance location; isTrustLocation is extracted from onlyTrustProblems so the import path and this decision share one rule.
  • getTemplatePackage and listTemplatePackages use the record state; the listing records the message in that entry's corrupt.problems instead of failing the whole store.
  • Three regression cases: the EACCES case for both readers; a package with a real digest mismatch under an unreadable record still reports invalid_package; an unverified package whose record was deleted is still refused.
  • Not included: the malformed-content case (a record that parses but is invalid). It keeps today's "absent" reading; whether it should also be named is the open scope question recorded on [Bug] An unreadable store metadata record is reported as an invalid template package #253, left for the maintainer.

Contract and boundary impact

  • Earliest changed layer: application (src/application/TemplateStore.ts).
  • Tool contract changes, and whether docs/public/tool-catalog.json was regenerated: none.
  • libuvcpp feature mapping changes: none.
  • Generated-code impact: none.
  • Evidence, unknown, or error-contract semantics: an unreadable store record now yields io_error (naming the path) from getTemplatePackage and a corrupt entry with that reason from listTemplatePackages, where the package was previously called invalid. not_found, invalid_package, template_exists, store_locked are unchanged.
  • Generated metadata, package, or installation impact: none.

Expected effects:

  • Read files on the local filesystem.
  • Write files, including generated workspaces and build directories.
  • Compile or link C++ via CMake.
  • Start or stop a process.
  • Open a listening socket.
  • Make an outbound network request.
  • Record or persist captured traffic.
  • Documentation or usability only; no runtime effect.
  • Not sure yet; needs maintainer guidance.

Evidence and regression coverage

  • Tests added or updated: three cases in src/application/TemplateStore.test.ts (17 → 20 in that file).
  • Base reproduction: observed at ffa8350 — the first case reports invalid_package and the two trust problems, as quoted above. The same case passes at 6702581.
  • Mutation probes, each run against the focused file and each killing exactly one case (20 tests otherwise green): (A) rethrow the validation error in getTemplatePackage → 1 failed; (B) drop the trust-only gate → 1 failed; (C) treat ENOENT as unreadable → 1 failed; (D) ignore the record state in the listing → 1 failed. The pristine copy was restored and re-ran 20 passed.
  • The exact command a reviewer can run: npm run test:local -- src/application/TemplateStore.test.ts
  • Remaining proof gaps:
    • The unreadable-record cases skip on Windows and as root, where the mode is not enforced; getuid?.() === 0 covers root on POSIX.
    • EIO is handled by the same branch but only EACCES/EISDIR were exercised.
    • The malformed-content branch is deliberately unchanged and is not claimed as fixed.

For evidence-bearing changes:

  • Observed, derived, and inferred claims remain distinguishable in the output.
  • Coverage that was not examined is reported as unknown, not complete.
  • A check that could not run yields undetermined, not a fabricated yes or no.
  • Resource kinds and provenance survive the boundary unchanged.

Validation performed

All commands ran in /tmp/wt-locale at 6702581, on Linux.

  • npm run test:local -- src/application/TemplateStore.test.ts — 20 passed (red before the change: 1 failed, 16 passed; the other two cases were added by this PR).

  • npx tsc --noEmit — exit 0.

  • npm run check:pr with LIBUVCPP_ROOT=/home/zwy/下载/libuvcpp-1.7.0-linux-x64, PKG_CONFIG_PATH=$LIBUVCPP_ROOT/lib/pkgconfig, LD_LIBRARY_PATH=$LIBUVCPP_ROOT/lib — exit 0; 78 files passed, 2 skipped; 1452 passed, 14 skipped (1466). The 14 skips are the same named lanes (native-probe build cache absent, opt-in published-package lane, Windows-only locators); none is claimed as covered.

  • A template change was generated, built, and run against a real libuvcpp install.

  • Not applicable (no template or libuvcpp-facing change).

Compatibility, safety, and release

  • Breaking changes or migration steps: a package whose store record cannot be read now fails with io_error where the validation error was reported; no on-disk format change. The malformed-content reading is unchanged.
  • libuvcpp version floor impact: none.
  • New network exposure or listening behaviour: none.
  • Package or release metadata impact: none.

Author readiness

Human owner: @Antruly

  • I reviewed the final diff and relevant existing code, understand the change and its edge cases, and take responsibility for the complete PR, including AI-assisted work.
  • I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps.
  • I declare this PR ready for initial maintainer review.

Before merge

  • This PR addresses a concrete problem or an agreed enhancement.
  • Material scope and authority questions are resolved, and any required maintainer scope decision covers the final diff. (The malformed-record content case is left open on [Bug] An unreadable store metadata record is reported as an invalid template package #253 and is not claimed.)
  • The PR has one focused outcome and the title follows type(scope): outcome.
  • Related issue is linked, or the reason for not linking one is stated above. (Fixes #253)
  • Tests cover the changed observable behaviour and its meaningful failure paths.
  • Owning docs, contracts, and generated metadata are updated where needed. (No docs or contracts declare the record's internals; the reader's docblock states the three answers.)
  • User-visible CLI or MCP changes include representative output. (No CLI/MCP change.)
  • I checked the final diff for secrets, unrelated cleanup, and unsupported claims.

@Antruly

Antruly commented Oct 18, 2026

Copy link
Copy Markdown
Owner Author

Review — fix(store): name an unreadable record instead of calling the package invalid

Reviewed at head 6702581 against main at ffa8350 (the merge of #252). No blocking findings. The three-answer reader is the right shape: the failure this fixes is exactly the third-state error the repository's own rules are written against — "could not look" being reported as "the package is a no".

What I verified independently

I reproduced the changed behaviours with a throwaway probe (deleted afterwards; git status clean), using EISDIR as well as the EACCES the tests use:

Scenario Result at 6702581
Unverified package, record replaced by a directory get → io_error: could not read <record>: EISDIR; list → 0 packages, one corrupt entry whose problem is that message
Verified package, record replaced by a directory get succeeds; list returns the package — a strict package does not need the record, and the change does not make it need one
Unverified package, record contents malformed ({ not json) invalid_package, as documented and unchanged
Unverified package, record unreadable and a file tampered invalid_package — a real package fact is not masked by the record
  • The mapping is the narrow one it claims to be. recordFailureOf fires only for unreadable + invalid_package + details that are all licence/provenance, so a digest mismatch, a missing README or an oversized file still reports as before. isTrustLocation is shared with onlyTrustProblems, so the import path and the read path cannot drift apart on what "trust" means.
  • Absence still fails closed. An unverified package whose record was deleted is refused, and the new case pins that.
  • Gates at this head: TemplateStore.test.ts 20 passed; tsc --noEmit, oxfmt --check, lint, verify:test-discovery clean. CI: every applicable check passes (the two skipped jobs are the libuvcpp/MSVC lanes selected off for this change).

Non-blocking (my judgement)

  1. trustOnlyDetails rebuilds a structured fact from rendered strings. problemsOf writes ${location}: ${message} and this function splits it back apart. It works today because locations are dotted paths without spaces, but a change to problemsOf (or a location containing ": ") would silently stop the mapping and quietly restore the old invalid_package answer. Carrying the structured problems through to recordFailureOf would make the coupling explicit.
  2. The listing drops the package's own trust problems when it substitutes the record message. The corrupt entry now says only "could not read the record"; a caller can no longer see "license: is required" alongside it. That the package problems are conditional on the record is a reasonable argument for the current shape — just worth deciding deliberately rather than by consequence.
  3. The malformed-record case is still read as absent — flagged as an open scope question in the body and on [Bug] An unreadable store metadata record is reported as an invalid template package #253, not claimed as fixed. I agree it is a separate decision; a record that parses but names the wrong id or schema is closer to corruption than absence, but nothing here depends on which way that goes.

I am marking this ready and approving it for the owner under today's standing authorization.

@Antruly
Antruly marked this pull request as ready for review October 18, 2026 12:37
@Antruly

Antruly commented Oct 18, 2026

Copy link
Copy Markdown
Owner Author

Owner approval. Approved at 6702581509db450e43d606a0c4349d0b77e7101e.

Reviewed in this comment. No blocking findings: the reader now distinguishes read/absent/unreadable, and the record name is substituted only when the package's sole problems are licence/provenance — a real package problem or a still-usable strict package is unaffected. I reproduced the changed behaviour independently with EISDIR as well as EACCES, including the case where the record is unreadable and a file is also tampered (invalid_package stands). The three non-blocking notes recorded there (the rendered-string coupling in trustOnlyDetails, the listing losing the package's own trust problems, and the deliberately open malformed-record question) do not hold the change.

At this head: TemplateStore.test.ts 20 passed, tsc --noEmit, oxfmt --check, lint and verify:test-discovery clean. All applicable checks pass. Readiness is declared (Owned by @Antruly; author readiness declared.).

Merging as a merge commit at the exact reviewed head.

Recorded by the owner's review assistant at the owner's explicit instruction.

@Antruly
Antruly merged commit 017a6ff into main Oct 18, 2026
19 of 20 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.

[Bug] An unreadable store metadata record is reported as an invalid template package

1 participant