Skip to content

Commit c2874f3

Browse files
feat(promote): warn when omit drops a credentialIds entry
An omitted credentialId is neutral. An entry omitted from a credentialIds list narrows which keys calls in the target may use, so the provider it was for falls back to Vapi's own key. The plan now names the entry and the file. Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
1 parent c4e7266 commit c2874f3

4 files changed

Lines changed: 103 additions & 7 deletions

File tree

‎docs/guides/promotion.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ left alone.
2121
5. Choose `bind` or `omit` for credentials and phone numbers in each target
2222
org. Pull generates stable aliases in `.env.<org>` from resources that
2323
already exist there; promotion never copies secrets or provisions numbers.
24+
An `omit` that drops an entry from a `credentialIds` list is flagged in the
25+
plan, because it narrows which keys calls in the target may use: see
26+
[Credential pins](credential-pins.md#promotion).
2427
6. Run the read-only plan for each transition before the first apply and
2528
confirm every create, update, and delete is expected.
2629

‎src/promote-cmd.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ async function transitionRun(
266266
);
267267
for (const change of plan.changes)
268268
console.log(` ${change.kind.padEnd(6)} ${change.path}`);
269+
for (const warning of plan.warnings) console.warn(` ⚠️ ${warning}`);
269270
if (plan.changes.length === 0) console.log(" no changes");
270271
if (plan.changes.length === 0) return false;
271272
const check = gates.checks.get(transition.source);

‎src/promotion.ts‎

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ export interface PromotionPlan {
5555
rootDir: string;
5656
target: string;
5757
changes: PromotionChange[];
58+
// Things a reviewer should know that don't stop the promotion.
59+
warnings: string[];
5860
}
5961

6062
export interface PromotionPlanOptions {
@@ -396,6 +398,8 @@ export function promotionBindingsApply(
396398
bindings: PromotionBindings,
397399
resolved: PromotionBindingsResolved,
398400
targetState: StateFile,
401+
// Collects the credentialIds entries the "omit" policy left out.
402+
omittedFromLists: string[] = [],
399403
): unknown {
400404
function credential(ref: string): string | undefined {
401405
const alias = resolved.credentialReverse.get(ref) ?? ref;
@@ -436,10 +440,15 @@ export function promotionBindingsApply(
436440
continue;
437441
}
438442
if (key === "credentialIds" && Array.isArray(child)) {
439-
output[key] = child
440-
.filter((item): item is string => typeof item === "string")
441-
.map(credential)
442-
.filter((item): item is string => item !== undefined);
443+
const kept: string[] = [];
444+
for (const item of child) {
445+
if (typeof item !== "string") continue;
446+
const bound = credential(item);
447+
if (bound) kept.push(bound);
448+
else
449+
omittedFromLists.push(resolved.credentialReverse.get(item) ?? item);
450+
}
451+
output[key] = kept;
443452
continue;
444453
}
445454
if (key === "phoneNumberIds" && Array.isArray(child)) {
@@ -599,14 +608,17 @@ export async function promotionPlanBuild(
599608
const targetByPath = new Map(target.map((file) => [file.path, file]));
600609
const sourcePaths = new Set([...wanted.values()].map((file) => file.path));
601610
const changes: PromotionChange[] = [];
611+
const warnings: string[] = [];
602612
for (const file of wanted.values()) {
603613
const parsed = await resourceData(file, options.rootDir, options.source);
604614
const canonical = referencesCanonicalize(parsed.data, options.sourceState);
615+
const omitted: string[] = [];
605616
const transformed = promotionBindingsApply(
606617
canonical,
607618
bindings,
608619
resolved,
609620
options.targetState,
621+
omitted,
610622
);
611623
if (
612624
extname(file.path) === ".ts" &&
@@ -621,12 +633,19 @@ export async function promotionPlanBuild(
621633
? file.content
622634
: renderContent(transformed, file.path, parsed.body);
623635
const existing = targetByPath.get(file.path);
624-
if (!existing || existing.content !== content)
636+
if (!existing || existing.content !== content) {
625637
changes.push({
626638
kind: existing ? "update" : "create",
627639
path: file.path,
628640
content,
629641
});
642+
// A credentialIds list is the only set of keys a call may use, so an
643+
// entry left out of it is not neutral the way an omitted credentialId is.
644+
for (const alias of new Set(omitted))
645+
warnings.push(
646+
`${file.path}: credentialIds entry "${alias}" is left out in ${options.target} (binding policy "omit"). Calls there can use only the keys still on the list, so that provider would run on Vapi's own key.`,
647+
);
648+
}
630649
}
631650
for (const file of target)
632651
if (
@@ -636,7 +655,12 @@ export async function promotionPlanBuild(
636655
)
637656
changes.push({ kind: "delete", path: file.path });
638657
changes.sort((left, right) => left.path.localeCompare(right.path));
639-
return { rootDir: options.rootDir, target: options.target, changes };
658+
return {
659+
rootDir: options.rootDir,
660+
target: options.target,
661+
changes,
662+
warnings,
663+
};
640664
}
641665

642666
export async function promotionPlanApply(plan: PromotionPlan): Promise<void> {

‎tests/promotion.test.ts‎

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,70 @@ test("promotion canonicalizes source UUIDs and applies credential and phone poli
284284
assert.match(content, /phoneNumberIds:\n\s+- target-phone/);
285285
assert.doesNotMatch(content, new RegExp(sourceTool));
286286
assert.doesNotMatch(content, new RegExp(sourceCredential));
287+
// The entry left out of the list is named, with the file it was in.
288+
assert.equal(plan.warnings.length, 1);
289+
assert.match(
290+
plan.warnings[0]!,
291+
/^assistants\/a\.md: credentialIds entry "unknown" is left out in target \(binding policy "omit"\)/,
292+
);
293+
} finally {
294+
await fx.cleanup();
295+
}
296+
});
297+
298+
test("promotion warns about a credentialIds entry it leaves out, and only then", async () => {
299+
const fx = await fixture();
300+
try {
301+
const sourceVoice = "33333333-3333-3333-3333-333333333333";
302+
await put(
303+
fx.root,
304+
"resources/source/squads/front-desk.yml",
305+
`name: Front Desk\nmembers: []\nmembersOverrides:\n credentialIds: [${sourceVoice}, llm]\n server:\n url: https://example.com\n credentialId: hooks\n`,
306+
);
307+
const build = (aliases: Record<string, "bind" | "omit">) =>
308+
promotionPlanBuild({
309+
rootDir: fx.root,
310+
source: "source",
311+
target: "target",
312+
patterns: ["squads/**"],
313+
sourceState: state({
314+
credentials: {
315+
voice: { uuid: sourceVoice },
316+
llm: { uuid: "source-llm" },
317+
hooks: { uuid: "source-hooks" },
318+
},
319+
}),
320+
targetState: state({
321+
credentials: {
322+
voice: { uuid: "target-voice" },
323+
llm: { uuid: "target-llm" },
324+
hooks: { uuid: "target-hooks" },
325+
},
326+
}),
327+
bindings: {
328+
credentials: { default: "bind", aliases },
329+
phoneNumbers: { default: "omit", aliases: {} },
330+
},
331+
});
332+
333+
// Every entry bound: nothing to say.
334+
assert.deepEqual((await build({})).warnings, []);
335+
// A single credentialId left out is what "omit" is for: no warning.
336+
assert.deepEqual((await build({ hooks: "omit" })).warnings, []);
337+
// A list entry left out narrows what the call may use: warn, by name,
338+
// even though the source wrote it as a UUID.
339+
const plan = await build({ voice: "omit" });
340+
assert.match(plan.changes[0]?.content ?? "", /credentialIds:\n\s+- llm\n/);
341+
assert.deepEqual(plan.warnings, [
342+
'squads/front-desk.yml: credentialIds entry "voice" is left out in target (binding policy "omit"). Calls there can use only the keys still on the list, so that provider would run on Vapi\'s own key.',
343+
]);
344+
345+
// Once the target file holds the promoted content there is no change,
346+
// and no warning to repeat.
347+
await promotionPlanApply(plan);
348+
const again = await build({ voice: "omit" });
349+
assert.deepEqual(again.changes, []);
350+
assert.deepEqual(again.warnings, []);
287351
} finally {
288352
await fx.cleanup();
289353
}
@@ -462,6 +526,10 @@ test("promotionConfigParse reads an org's optional check gate and rejects a non-
462526
const parsed = promotionConfigParse(config("dev-core"));
463527
assert.deepEqual(
464528
[parsed.orgs.dev?.check, parsed.orgs.prod?.check, error],
465-
["dev-core", undefined, "org dev.check must be a check name from vapi-checks.yml"],
529+
[
530+
"dev-core",
531+
undefined,
532+
"org dev.check must be a check name from vapi-checks.yml",
533+
],
466534
);
467535
});

0 commit comments

Comments
 (0)