Repository navigation
fix(cli): say when template copy or layout expand replaced demo media - #6567
Conversation
Copying a template swaps Astryx demo images and video for placeholders, but the receipt never said so. `template.copy` now reports `demoMediaReplaced`, and the text output names the file whose media the consumer has to supply.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
AI review status for this pull request.
|
Expanding a layout splices template blocks through the same demo media replacement as a template copy, but `layout.expand` never said so. It now reports `demoMediaReplaced` from the copy path's shared count, and the text output states it, as a trailing comment when the code is printed.
There was a problem hiding this comment.
Thanks for restoring this disclosure in both places — the change looks ready to approve.
- Both receipts now carry
demoMediaReplaced:template.copyfor the written file, andlayout.expandsummed over the template blocks it splices (a block referenced multiple times counts once, matching how it is spliced once). At0the JSON field is present and the text output stays silent. - The text lines name what the consumer must fix without implying media was installed — e.g. that images now show a neutral placeholder and videos have an empty source. When
layout expandprints the code instead of writing it, the code is emitted unchanged and the disclosure follows as a//comment, so piped output is still valid TSX. - The field is projected consistently as the CLI contract requires: canonical types, function docs, README response rows, command help, and contract tests all land together, and the new receipt tests cover image, video, and no-media cases with JSON and text in agreement.
[Automated review]
| import {stripTemplateAssetRefs} from '../../../foundation/discovery/template-adapter.mjs'; | ||
|
|
||
| /** The template-fixture namespace Astryx demo media lives under. */ | ||
| const FIXTURE_NAMESPACE = '/template-assets/'; |
# Conflicts: # packages/cli/README.md
PR Analysis Report
|
Show now replaces demo media the way copy does, so it reports the count the way #6567 has copy report it: demoMediaReplaced on template.show, and in text a stderr line in the copy receipt wording so stdout stays the exact source. The helper replaceDemoMedia sits beside stripTemplateAssetRefs in the template adapter.
There was a problem hiding this comment.
Thanks for restoring this disclosure in both places — the change looks ready to approve.
- Both receipts now carry
demoMediaReplaced:template.copyfor the written file, andlayout.expandsummed over the template blocks it splices (a block referenced multiple times counts once, matching how it is spliced once). At0the JSON field is present and the text output stays silent. - The text lines name what the consumer must fix without implying media was installed — images now show a neutral placeholder and videos have an empty source, and the consumer is told to supply their own media. When
layout expandprints the code instead of writing it, the code is emitted unchanged and the disclosure follows as a line comment, so piped output is still valid TSX. - The field is projected consistently as the CLI contract requires: canonical types, function docs, README response rows, command help, and contract tests all land together, and the new receipt tests cover image, video, and no-media cases with JSON and text in agreement.
[Automated review]
There was a problem hiding this comment.
Thanks for restoring this disclosure in both places — the shape of the change looks right, with one counting fix needed before it lands.
-
Both receipts now carry
demoMediaReplaced:template.copyfor the written file, andlayout.expandsummed over the template blocks it splices (a block referenced multiple times counts once). At0the JSON field is present and the text output stays silent, and whenlayout expandprints the code the disclosure follows as a//comment so piped output stays valid TSX. The field is also projected consistently — types, function docs, README rows, command help, and contract tests all land together. -
One defect in how the count is computed: it is the drop in
/template-assets/substring occurrences, not the number of references replaced. A single reference whose URL contains a second fixture path — e.g.'/template-assets/a.png?f=/template-assets/b.png', which the existing transformer tests treat as one reference replaced whole, query included — reports2instead of1, so the receipt would send the caller looking for a second placeholder that does not exist. No shipped template uses that form today, but the count is the point of the field, so please count the replacements actually made and add synthetic unit tests for that form and for a mixed poster-plus-video source (catalog-picked templates cannot supply either).
[Automated review]
| const output = stripTemplateAssetRefs(source); | ||
| return { | ||
| source: output, | ||
| demoMediaReplaced: countFixtureRefs(source) - countFixtureRefs(output), |
There was a problem hiding this comment.
This counts the drop in /template-assets/ substring occurrences, not the number of references replaced. One replaced reference can contain the substring twice — e.g. '/template-assets/a.png?f=/template-assets/b.png', which the existing fixture-refs test pins as a single reference replaced whole (query included) — and this returns 2 for it (likewise for a nested-segment single reference). Please count the replacements the transformer actually makes, and add synthetic unit tests for that form and a mixed poster-plus-video source.
…out half Review fix. The count was the drop in '/template-assets/' substrings, so one reference whose query held a second fixture path counted twice. The count now comes from the replacement pass itself (replaceDemoMedia in the template adapter, the same code as #6870, so the two PRs merge cleanly), one per replaced reference. copy.mjs uses it instead of its own helper. The layout half is gone: #6615 removes the layout command, so layout expand no longer gets a receipt field, and the changeset names template only.
There was a problem hiding this comment.
Thanks for restoring this disclosure — the change looks ready to approve.
- The
template.copyreceipt now always carriesdemoMediaReplaced(0when nothing was replaced), and the text output adds one line naming the written file only when the count is above zero, so callers learn the scaffold has placeholder media to swap for their own. - The count now comes from the replacement pass itself — one per replaced reference, including a single reference whose URL carries a second fixture path — and synthetic tests pin that form, a poster-plus-video source, and the prose and third-party cases that must count zero.
- The field is projected consistently as the CLI contract requires: canonical type, consumer docs, the generated README row, and the API and CLI contract tests all land together, with JSON and text in agreement.
[Automated review]
#6887 restored the layout command, so the layout half this PR dropped for #6615 applies again: layout expand splices template blocks and replaces their demo media without saying so (AST-028 FR11). This restores it as it was before that drop, with one change: the count comes from replaceDemoMedia in the template adapter, the same pass template copy uses, so one reference counts once however many fixture paths its URL carries.
There was a problem hiding this comment.
Thanks for restoring this disclosure in both places — the change looks ready to approve.
- Both receipts now carry
demoMediaReplaced:template.copyfor the written file, andlayout.expandsummed over the template blocks it splices (a block referenced multiple times counts once, matching how it is spliced once). At0the JSON field is present and the text output stays silent. - The count comes from the replacement pass itself — one per replaced reference, including a single reference whose URL carries a second fixture path — and synthetic tests pin that form, a poster-plus-video source, and the prose and third-party cases that must count zero. The text lines name what to fix without implying media was installed, and when
layout expandprints the code the disclosure follows as a comment so piped output stays valid TSX. - The field is projected consistently as the CLI contract requires: canonical types, function docs, README rows, command help, and contract tests all land together, with JSON and text in agreement.
[Automated review]
* fix(cli): print the same template source that copy writes astryx template <name> printed the file as it is on disk, while astryx template <name> <path> swapped demo media that only Astryx previews serve for a placeholder. The show leaf now runs the same swap, so both return the same source. * fix(cli): template show says how many demo media references it replaced Show now replaces demo media the way copy does, so it reports the count the way #6567 has copy report it: demoMediaReplaced on template.show, and in text a stderr line in the copy receipt wording so stdout stays the exact source. The helper replaceDemoMedia sits beside stripTemplateAssetRefs in the template adapter. * fix(cli): count each replaced demo media reference once demoMediaReplaced counted the drop in /template-assets/ substrings, so one reference whose URL carried a second fixture path counted twice. It now counts the references the replacement pass actually replaces. stripTemplateAssetRefs output is unchanged.
Mechanical refresh. #6621 (merged as 31feb21) moved template copy's source read before the write and wrapped the mkdir and write in ERR_WRITE_FAILED; this PR changed that read to replaceDemoMedia(). The resolution keeps both: the replaceDemoMedia() read before the guarded mkdir+write. #6618 (merged as 6e56409) changed the generated README tables, so they are regenerated.
User impact
Anyone who scaffolds template source that carries Astryx demo images or video with
astryx template <name> <path>(ortemplate(name, {targetPath})). The copy already replaces those references, images with a neutral inline placeholder and videos with an empty source, so the output does not depend on the Astryx preview host. But the receipt never said so:template.copywas{template, outputDir, fileName, filesCopied}and printed onlyCopied template to app/page.tsx. The caller was never told that the page now has placeholder media to replace.After the change the receipt carries
demoMediaReplaced: how many references became placeholders,0when there were none. The text output adds one line naming the file, e.g.Replaced 1 Astryx demo media reference in app/page.tsx: images now show a neutral placeholder and videos have an empty source. Supply your own media there.Problem and solution fit
api/template/copy/copy.mjsruns the fixture replacement and returns a receipt that predates any disclosure requirement.The count comes from the replacement pass itself.
replaceDemoMedia()infoundation/discovery/template-adapter.mjsreturns the replaced source plus one count per replaced reference. A reference is replaced whole, query included, however many fixture paths its URL carries.stripTemplateAssetRefs()returns its.source, so its output is unchanged byte for byte. #6870 carries the identical adapter change, so the two PRs merge cleanly in either order.Expected behavior and authority
docs/specs/AST-028/spec.md(authority: current), FR11: "A successful copy operation MUST tell the consumer when Astryx demonstration media was replaced and identify the generated file or replacement points they need to customize. The receipt MUST not imply that production-ready media was installed."docs/specs/AST-017/spec.md(authority: current), DEC-4: every response field keeps "its canonical type, contract tests, applicable text output, and complete consumer documentation aligned in the same change."demoMediaReplacedhas the typedef, contract tests, the text line, the FunctionDocreturnsentry and the README response-type row.docs/architecture/cli-surface.md(authority: current), INV4: "Human output is a projection of the JSON, produced only by the formatters." The text line is rendered fromdemoMediaReplacedthroughemit; nothing new is written to stderr.Compatibility (AST-017 FR5/FR13): an additive field on
template.copy; every existing field is unchanged.Smallest restoration
foundation/discovery/template-adapter.mjs:replaceDemoMedia(), the existing replacement pass plus the count;stripTemplateAssetRefs()delegates to it.api/template/copy/copy.mjs: the copy uses it and addsdemoMediaReplacedto the receipt.template.type.mjs,template.doc.mjs: the field's type and consumer description.commands/template.mjs: the text projection, one line, printed only when the count is above zero.foundation/response/response-types.doc.mjsand the regenerated README row: thetemplate.copydescription names the field.Evidence
astryx --json template centered-hero ./appreturned{"template":"centered-hero","outputDir":"app","fileName":"page.tsx","filesCopied":1}, and the text said onlyCopied template to app/page.tsx, although the hero image in the written file had been replaced."demoMediaReplaced": 1and the text line above.0and prints nothing new. The existing copy, overwrite and traversal tests pass unchanged.api/template/copy/copy.receipt.test.mjsandclients/cli/commands/template.copy-receipt.test.mjscover an image page, a video block and a no-media page, and check that JSON and text agree.template-adapter.fixture-refs.test.mjscovers the count: one reference whose query holds a second fixture path counts 1, a poster plus a video counts 2, and a prose mention, a third-party URL or source with no fixture counts 0. The query case fails against the old substring count.check:cli-structure,check:changesets,readme:check, both typechecks,cli-api-types-verify, eslint and prettier pass.Scope
layout expandhalf is gone, because Remove the experimental layout command #6615 removes that command.replaceDemoMedia()is internal; the package API does not export it.Layout half restored (head cce9cd5, on main ebd939b)
#6887 restored the
layoutcommand, so thelayout expandhalf that this PR dropped for #6615 applies again.layout expandsplices template blocks and replaces their demo media without saying so (AST-028 FR11). It is restored as it was before the drop, with one change: the count comes fromreplaceDemoMedia(), the same pass template copy uses, so one reference counts once however many fixture paths its URL carries.layout/expandimports it through the template barrel (api/template/template.mjs), the same way the code before this PR tookstripTemplateAssetRefs. A directfoundation/discoveryimport fails INV21. The barrel is internal; the package API exports onlytemplate()from it.Evidence on main ebd939b plus this head: the full CLI node suite (346 files, 5,331 tests) and every gate listed above pass. With
layout/expand/expand.mjsreverted, all 5 layout receipt tests fail (expected undefined to be 3).Mechanical refresh after #6618, #6621 and #6870 (head 6c68af9, on main eb58bba)
#6618, #6585, #6621 and #6870 merged between 16:14 and 16:16 PT. This PR then conflicted with #6621 in
api/template/copy/copy.mjsand with #6618 in the generated README tables. This refresh merges main and resolves both. It adds nothing new to the PR's own change:api/template/copy/copy.mjs. fix(cli): a failed write reports ERR_WRITE_FAILED, not a raw Node errno #6621 moved the source read before any write and wrapped themkdirand the write inERR_WRITE_FAILED. This PR changes that read toreplaceDemoMedia(). The resolution keeps both: thereplaceDemoMedia()read, then fix(cli): a failed write reports ERR_WRITE_FAILED, not a raw Node errno #6621's guardedmkdirand write. Every line this PR adds or removes in the file, against its merge base, is the same before and after the refresh.README.md. Main's tables, which fix(cli): say when a command did nothing (upgrade sourcePathFound, doctor validated) #6618 re-padded, regenerated withpnpm -F @astryxdesign/cli readme. This PR's own README lines are the same before and after.foundation/discovery/template-adapter.mjsandtemplate-adapter.fixture-refs.test.mjsdropped out of the diff. TheirreplaceDemoMedia()hunk and test block are byte-identical to fix(cli): print the same template source that copy writes #6870's hunks (the same added and removed lines), and fix(cli): print the same template source that copy writes #6870 merged at 16:16:49, so main already has them. The refreshed branch's copy of both files now equals main's. The whole-file blobs differ from fix(cli): print the same template source that copy writes #6870's head only because feat(cli): build tells parts from pages by the system's components; templates declare keywords #6805 also edited the adapter.Evidence: the refreshed tree equals the end-state tree tested before the batch (main f261d2f + #6951 + #6618 + #6585 + #6621 + #6870 + this refresh), minus #6951's one line. That tree passed every gate (readme:check, both typechecks, cli-api-types-verify, check-cli-structure, check-changesets, check-knowledge, check:repo) and the full CLI node suite (357 files, 5,650 tests).
Merge note
Squash-merged at 16:45:45 PT on 2026-10-05, pinned to head 6c68af9, as 5e7c207. All six required contexts were green on that head. The AI review's approve was still pinned to the pre-refresh head cce9cd5, because its queue had no worker online, so no fresh review could start. The merge relied on that verdict because the refresh is proven line-for-line identical in the PR's own diff (trace above), and the owner's word to merge covered it.