Skip to content

test(artifacts): make same-size carrier rewrites observable on coarse timestamps - #10155

Open
SahinurDEV wants to merge 3 commits into
morluto:mainfrom
SahinurDEV:fix/same-size-carrier-rewrite-tests
Open

SahinurDEV wants to merge 3 commits into
morluto:mainfrom
SahinurDEV:fix/same-size-carrier-rewrite-tests

Conversation

@SahinurDEV

Copy link
Copy Markdown
Contributor

Summary

Four artifact-reader tests rewrite the carrier in place with bytes of the same size and then expect reason: "integrity". Carrier identity is checked with sameRegularFileState (dev, ino, size, mode, mtime/ctime). On filesystems whose timestamps advance in coarse ticks (for example ext4 on Linux 6.12, where two writes a few milliseconds apart get identical mtimeNs/ctimeNs), the rewrite is invisible to that check, so the tests fail or flake depending on how fast the reader runs. No issue is linked; this is a test-reliability fix found while running targeted suites.

Problem and expected behavior

Smallest trigger: on Linux 6.12.113 / ext4, Node 24.22.1:

await writeFile(p, Buffer.alloc(1024, 1)); const a = await stat(p, { bigint: true });
await writeFile(p, Buffer.alloc(1024, 2)); const b = await stat(p, { bigint: true });
a.mtimeNs === b.mtimeNs // true on some runs

Affected tests on main (a016743):

  • Uf2ArtifactReader.test.ts › rejects a forged region entry and a changed carrier (fails every run here: promise resolved "Readable{…}" instead of rejecting)
  • NodeSeaArtifactReader.test.ts › rejects post-classification carrier mutation before publishing Node SEA facts: valid replacement / malformed blob (1–2 of 2 fail per run)
  • deno/DenoStandaloneArtifactReader.boundaries.test.ts › rejects carrier mutation between physical member reads (intermittent)
  • pyinstaller/PyInstallerBoundaries.test.ts › binds materialization to the inventoried digest and checks cached carrier freshness (intermittent; "first" and "other" have the same length)

Expected: these tests verify that a changed carrier is rejected, independent of host timestamp granularity.

Change and scope

Test-only. Each test now records the carrier's stats before the same-size rewrite and afterwards moves mtime forward by one second with utimes (or FileHandle.utimes inside the Deno read hook). This follows the existing pattern in tests/boundary/filesystem/directoryArtifactReaderOpen.test.ts. The tests still exercise the real identity check; they just make the mutation observable to it on every filesystem.

Intentionally not included: no production change to sameRegularFileState or ArtifactFileSource. Detecting same-size, same-tick rewrites would need content rehashing on every open, which is a design decision for maintainers, not a test fix.

Follow the contribution scope.

Contract and boundary impact

  • Semantic owner and earliest changed stage: tests only (src/artifacts/**.test.ts); no producer or consumer changes.
  • Contribution scope fit and linked maintainer decision: not applicable (focused test fix).
  • CLI and MCP/tool-catalog contract: none.
  • Provider, bridge, target-format, or platform compatibility: none; makes tests pass on coarse-timestamp filesystems.
  • Evidence, artifact, provenance, or reconstruction contract: none.
  • Target selection, authority, upstream behavior, and cleanup details (if applicable): not applicable.
  • Generated metadata (docs/public/product-catalog.json), package, or installation impact: none.

Expected effects (check known effects; use documentation-only on its own).
Unchecked items do not establish absence; leave uncertainties visible.

  • Read existing files or captured data.
  • Launch or attach to a process.
  • Inject instrumentation or run scripts/code.
  • Change process memory, registers, files, or configuration.
  • Contact network services.
  • Recover protected code or work around protections.
  • Documentation or usability only; no target interaction.
  • Not sure yet; investigation or maintainer guidance needed.

Evidence and regression coverage

  • Tests added or updated: the four tests listed above.
  • Base reproduction or other evidence: executed. On base, npx vitest run src/artifacts reported 2 failed | 1745 passed | 1 skipped, with the Uf2 and Node SEA tests failing; a second base run failed the Deno and PyInstaller tests instead. Uf2ArtifactReader.test.ts alone failed 2/2 runs.
  • User-visible CLI/MCP output (if applicable): not applicable.
  • Remaining proof gaps: not run on macOS/Windows (APFS/NTFS have finer timestamps, so behavior there is unchanged).

For evidence-bearing changes:

  • Observed, derived, and inferred claims remain distinguishable.
  • Artifact identity, source provenance, and failed attempts remain preserved.
  • Unsupported, incomplete, unavailable, or uncertain outcomes remain visible.

Validation performed

  • npx vitest run src/artifacts/Uf2ArtifactReader.test.ts src/artifacts/NodeSeaArtifactReader.test.ts (3 runs) — 55 passed each run
  • npx vitest run src/artifacts (3 runs) — 1747 passed, 1 skipped each run
  • npm run typecheck — passed
  • npx oxlint <changed files> — no new findings (only existing no-this-alias warnings elsewhere in PyInstallerBoundaries.test.ts)
  • npx oxfmt --check src/artifacts — all files formatted

Compatibility, safety, and release

  • Breaking changes or migration steps: none.
  • Real Hopper/Ghidra, browser, or OS coverage: Linux 6.12 / ext4 / Node 24.22.1 only.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: test-only.

Author readiness

Human owner: @SahinurDEV

  • 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 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.
  • Tests cover changed observable behavior and meaningful failure paths.
  • Owning docs, contracts, and generated metadata are updated where needed.
  • User-visible CLI/MCP changes include representative output.
  • I checked the final diff for secrets, unrelated cleanup, and unsupported claims.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-22T12:37:57.381777Z 9641cd8 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b058a9418c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

// The replacement keeps the carrier size, and filesystems with coarse
// timestamps can leave mtime unchanged within one tick. Move mtime so
// the mutation is observable independently of timestamp granularity.
utimesSync(args[0], before.atime, new Date(before.mtimeMs + 1000));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Advance mtime past the filesystem timestamp quantum

If these tests run with tmpdir() on a filesystem with 2-second timestamp ticks, such as FAT, mtimeMs + 1000 can round back to the original mtime; if ctime is also unchanged within its tick, sameRegularFileState still sees identical metadata and the integrity assertion can resolve instead of reject. The same delta is used in the UF2, Deno, and PyInstaller tests; use a delta beyond that quantum or verify the post-utimes stat changed.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good point. In 4abf945 I moved mtime forward by 10 s instead of 1 s in all four tests (UF2, Node SEA, Deno, PyInstaller), so the bump stays visible even with 2 s FAT timestamp ticks.

Resolve the Uf2ArtifactReader.test.ts conflict by following morluto#13372, which
removed the UF2 reader identity test during numbering consolidation.
Keep the 10 s mtime bump in the Node SEA, Deno, and PyInstaller tests.

Signed-off-by: Sahinur <[email protected]>
@greptile-apps

greptile-apps Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Low impact] The reviewed changes appear safe to merge.

Summary

The PR makes same-size rewrites visible in three artifact-reader test files by moving mtime forward ten seconds.

  • Artifact-reader tests make same-size carrier rewrites visible on coarse-tick filesystems.

Reviews (2) · Last reviewed commit: "Merge upstream/main into fix/same-size-c..." · Reviewed by Greptile

@morluto morluto added the area: evidence Evidence, artifacts, and reconstruction label Nov 22, 2026
@morluto

morluto commented Nov 24, 2026

Copy link
Copy Markdown
Owner

@SahinurDEV thanks for the PR — there is 1 open review thread here:

Could you address or reply to this? Once it's resolved and CI is green we can take another look.
cc @gensokyo-dev @dandgabr

This branch has not been deployed

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

Labels

area: evidence Evidence, artifacts, and reconstruction

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants