Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions testing/rebrand.test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
29 changes: 21 additions & 8 deletions tooling/rebrand/rebrand.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,21 @@ function literalPairs() {
];
}

// Secret refs: `secret://<workspace>/<project>/…`. 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 `<reponame>`,
// including both halves of `secret://<slug>/<slug>/`, 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
Expand All @@ -303,14 +318,6 @@ function regexPairs(files) {
replacement: () => `SITE_NAME = ${JSON.stringify(productname)}`,
label: "site name seam",
},
// Secret refs: `secret://<workspace>/<project>/…`. 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);
Expand Down Expand Up @@ -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));

Expand Down
Loading