Repository navigation
fix(cli): a long-running caller sees an edit to a doc file it already read - #7998
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
AI review status for this pull request.
|
PR Analysis Report📚 Storybook Preview🧪 Sandbox PreviewNo new or modified components detected. Bundle Size SummaryNo component packages changed. Accessibility AuditStatus: No accessibility violations detected. Visual Regression46 of 494 shot(s) changed. A change here is a question, not a failure: check whether the after is the
and 26 more. Generated by PR Enrichment workflow | Storybook | Sandbox | View full report |
There was a problem hiding this comment.
The fix works for .doc.mjs docs: in one process, edited topics, guides and component docs now show up in docs(), component() and search() on the next call, and the new regression tests cover each case. One change is needed before merging: importCurrent in packages/cli/foundation/doc-compiler/import.mjs shares one re-imported module per file across all three importers, so after an installed integration's .doc.ts is rewritten, a long-running search() returns a description that astryx search --json in a new process does not. Keeping the shared first-import stamp but holding the re-imported module per importer (for example seen.changed[kind] ??= loadFresh(file)), with a .doc.ts test that reads through loadDocs before loadComponentDoc after an edit, fixes it. Separately, docs('authoring') still lists an edited CLI guide's old summary, so the changeset's docs() claim should be narrowed or the CLI's own docs tree refreshed on a change.
[Automated review]
| const seen = imported.get(file); | ||
| if (!seen) { | ||
| imported.set(file, {stamp}); | ||
| return load(file); | ||
| } | ||
| if (seen.stamp === stamp) return seen.changed ?? load(file); | ||
| const changed = loadFresh(file); | ||
| imported.set(file, {stamp, changed}); | ||
| return changed; |
There was a problem hiding this comment.
After a change this entry is shared by all three importers, so whichever re-imports first decides what the others get. For a .doc.ts under node_modules, search's native reader then serves the module jiti loaded, and a long-running search() disagrees with astryx search --json; in the opposite order importDocModule gets the native failure until the next change. Keeping this shared first-import stamp but holding the re-imported module per importer (for example seen.changed[kind] ??= loadFresh(file)) gives each reader a fresh process's answer.
…CLI's own docs tree after an edit
0e63268 to
49b42aa
Compare
There was a problem hiding this comment.
This looks ready to merge: in one long-running process, docs(), component() and search() now return a doc file's edited content on the next call, matching what a new astryx process returns, and the new tests fail without the change. The per-importer fresh modules and the refreshed CLI docs tree also settle the two earlier change requests. One optional follow-up: component() still keeps the first-read text of a .doc.js from a package whose package.json has no "type" field, because importDocModule's fresh read goes through require() there; evicting the file's require cache entry and importing a fresh file URL reloads it.
[Automated review]
| export function importDocModule(file) { | ||
| return importUserModule(file); | ||
| return importCurrent(file, 'doc', importUserModule, changed => | ||
| importUserModule(changed, {fresh: true}), |
There was a problem hiding this comment.
After an edit this re-reads the file with importUserModule(changed, {fresh: true}), whose .js branch uses require() unless the nearest package.json says "type": "module". A .doc.js written with export default in a package with no "type" field (Node loads it as an ES module by syntax detection) then comes back as the module Node already holds, so component() keeps the first-read text while search() shows the edit. Evicting the file's require cache entry and importing a fresh file URL reloads that file, a CommonJS one and a "type": "module" one alike; the same in the native and template importers' fresh reads also covers a CommonJS .doc.js that one of them reads first after a change.
User impact
A process that calls the CLI API more than once — a docs site's search endpoint, an agent harness, anything that keeps Node running between calls — never saw an edit to a doc file it had already read. After editing a topic, a guide, a component doc or an integration's doc,
docs(),component()andsearch()kept returning the old text until the process restarted. Adding or removing a file was seen; editing one was not.Problem and solution fit
import(), and Node keeps one module per URL for the life of the process; jiti does the same for.tsdocs. On top of that, the reader memoized each lowered file for the life of the process.fs, so the doc files themselves were never part of that check.The fix makes the importer content-aware and lets the two caches above see the files it imports.
Expected behavior and authority
The search adapter already promises that "an edited doc in a linked package is seen on the next call" (
api/search/_adapter.mjs). The reader's contract test, "hands readers the module's own doc, as main always did", still holds: an unchanged file is imported exactly as before.Smallest restoration
foundation/doc-compiler/import.mjs: each importer imports a file as before until it changes (so readers keep the module's own doc). When the file's stamp changes, each importer (plain import, jiti, JSX jiti) imports it once more, fresh and in its own way, and shares that module until the next change. So a.doc.tsread after an edit gives each reader what a new process would. Each import counts as a read of the file for the running operation.foundation/doc-compiler/read.mjs: the lowered-file memo is kept per file stamp, so an edited file is lowered again.api/docs/_adapter.mjs: the CLI's own tree files and authoring docs were loaded once per process, sodocs('authoring')kept an edited guide's old summary. They now come fromreusedWhileUnchanged, which keeps the loaded value while every file and folder it read is unchanged.foundation/fs/read-record.mjs:recordContentRead(file)adds a file read withoutfs(a module import) to the running record. A run inside another records into both, and a kept value's reads count for the operation that asks for it, so search's own reuse still sees those files.fileStamp(size, modification time, change time, inode) is now the state it compares, so a rewrite that keeps size and modification time, as an npm reinstall does, also counts as a change.Evidence
colortopic, theauthoring/quick-startguide, the CoreButtondoc and a linked integration's topic all kept their old text indocs()/component(), andsearch()didn't find a word added to any of them.docs('authoring')also kept listing an edited guide's old summary.search()finds the new word in each, anddocs('authoring')lists the new summary.docs authoring --index660 vs 655 ms,docs color671 vs 665,search button1847 vs 1841,component Button --dense689 vs 686.docs()call costs about 1 ms more (5.3 → 6.3 ms), because it checks the CLI tree's files for changes.read.test.mjs(an edited.mjsdoc, an edited.tsdoc, the whole-project memo, and a fix after a broken edit), inread-record.test.mjs(a recorded import; a same-size, same-mtime rewrite) and inapi/search/_adapter.test.mjs(an edited integration doc in a linked package is re-gathered with its new text). With the importer change reverted, all five of those reader and search tests fail. A.doc.tsread throughloadDocsand thenloadComponentDocafter an edit checks that each importer keeps its own module; it fails when one module is shared.read-record.test.mjsalso covers nested runs andreusedWhileUnchanged(keep, reload after an edit,fresh, a kept value's reads counted, retry after a failure).Scope
Testing
pnpm vitest run --project node packages/cli: everything passes except two tests infoundation/release/cache.test.mjs(process-group checks around an npm install), which fail the same way on main on the machine I ran them on. Under the full parallel load,docs-homes.test.mjshit its 60 s limit once; run alone it passes in 15.7 s (16.2 s on main).pnpm check:repo,check:knowledge,check:changesets, changeset coverage against v0.7.4, the CLI README check, and eslint on the changed files: all pass.typecheck:strictreports only the two@astryxdesign/theme-neutral/builterrors a tree without a root build always has.