diff --git a/testing/rebrand.test.sh b/testing/rebrand.test.sh index 8ccacfe..309bef4 100755 --- a/testing/rebrand.test.sh +++ b/testing/rebrand.test.sh @@ -148,6 +148,15 @@ check "a name containing the baseline's name survives three passes" \ "$contains" apps/web/lib/site.ts 'export const SITE_NAME = "Chatbot";' \ 'export const SITE_NAME = "Chatbot 2";' 3 +# A product that keeps the baseline's own name. The guard holds every bare +# `ai-chatbot`, so a secret-ref rule run after it never saw the ref and the +# product shipped `secret://ai-chatbot/ai-chatbot/…` — the repo as its +# workspace, refused on every resolve (vijayakrishnans/ai-chatbot). +same='{"reponame":"ai-chatbot","productname":"Ai Chatbot","orunWorkspace":"org_269510fca1b34bdd82e5ebf19edcaea3"}' +check "a product named like the baseline still gets its workspace in secret refs" \ + "$same" infra/terraform/cloudflare-r2/component.yaml ' CLOUDFLARE_ACCOUNT_ID: "secret://ai-chatbot/ai-chatbot/{{ .environment }}/CLOUDFLARE_ACCOUNT_ID"' \ + ' CLOUDFLARE_ACCOUNT_ID: "secret://org_269510fca1b34bdd82e5ebf19edcaea3/ai-chatbot/{{ .environment }}/CLOUDFLARE_ACCOUNT_ID"' 3 + # --verify runs after every rebrand. Without the product's values it cannot # tell the product's own identity from a leftover; with them it can. A real # leftover must fail it either way. diff --git a/tooling/rebrand/rebrand.mjs b/tooling/rebrand/rebrand.mjs index b2e4c1e..72f846f 100644 --- a/tooling/rebrand/rebrand.mjs +++ b/tooling/rebrand/rebrand.mjs @@ -293,6 +293,21 @@ function literalPairs() { ]; } +// Secret refs: `secret:////…`. The workspace segment is +// ANY segment — a ws_… id or a slug. This rule runs BEFORE the guard, not +// among the regex pairs: when the product keeps the baseline's own name +// (reponame === baseline.slug), the guard holds every bare ``, +// including both halves of `secret:////`, and a rule run after it +// never sees the ref — the product shipped refs naming the repo as its +// workspace, and every secret resolve was refused. It must also precede the +// repo-slug pass, which would otherwise rewrite only the project half. +// Re-running it over its own output writes the same ref, so it needs no guard. +const SECRET_REF_RULE = { + re: new RegExp(`\\bsecret://[A-Za-z0-9_-]+/${rx(baseline.slug)}/`, "g"), + replacement: () => `secret://${orunWorkspaceSlug}/${reponame}/`, + label: "secret ref workspace/project", +}; + function regexPairs(files) { const list = [ // The display-name seam (apps/web/lib/site.ts). JSON.stringify writes a @@ -303,14 +318,6 @@ function regexPairs(files) { replacement: () => `SITE_NAME = ${JSON.stringify(productname)}`, label: "site name seam", }, - // Secret refs: `secret:////…`. MUST precede the - // repo-slug pass, which would otherwise rewrite only the project half. The - // workspace segment is ANY segment — a ws_… id or a slug. - { - re: new RegExp(`\\bsecret://[A-Za-z0-9_-]+/${rx(baseline.slug)}/`, "g"), - replacement: () => `secret://${orunWorkspaceSlug}/${reponame}/`, - label: "secret ref workspace/project", - }, ]; const bases = workerBases(files); @@ -448,6 +455,12 @@ for (const file of files) { }); }); + text = text.replace(SECRET_REF_RULE.re, (m) => { + const to = SECRET_REF_RULE.replacement(); + if (to !== m) count(SECRET_REF_RULE.label); + return hold(to); + }); + // What a previous pass already wrote stays as written. for (const value of guarded) text = text.split(value).join(hold(value));