Skip to content

Commit dbca664

Browse files
fix(validate): keep the credential providers record where the org's commit step stages it
An org whose state is still in the layout from before state/ gets its record at resources/<org>/.vapi-credential-providers.json, beside the old org pin. A commit step written for that layout stages resources/, so the record is committed and validate stops reporting credential-pin-unchecked on every run. An org whose state is in state/<org>/ keeps state/<org>/credential-providers.json. npm run migrate moves the record with the state file and the pin. validateCredentialPins takes the file's name from its caller, so the finding names the file the org actually has. Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
1 parent 977d93a commit dbca664

13 files changed

Lines changed: 248 additions & 101 deletions

‎docs/guides/commands.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ tell it. Nothing changes inside the files.
148148
| --- | --- |
149149
| `.vapi-state.<org>.json` | `state/<org>/state.json` |
150150
| `resources/<org>/.vapi-org.json` | `state/<org>/org.json` |
151+
| `resources/<org>/.vapi-credential-providers.json` | `state/<org>/credential-providers.json` |
151152
| `.vapi-state-hash/<org>/` | `state/<org>/local/baselines/` |
152153
| `.vapi-state.<org>.snapshots/` | `state/<org>/local/snapshots/` |
153154

@@ -269,6 +270,7 @@ for dir in state/*/; do
269270
org=$(basename "$dir")
270271
if [ -f "state/$org/state.json" ]; then mv "state/$org/state.json" ".vapi-state.$org.json"; fi
271272
if [ -f "state/$org/org.json" ]; then mv "state/$org/org.json" "resources/$org/.vapi-org.json"; fi
273+
if [ -f "state/$org/credential-providers.json" ]; then mv "state/$org/credential-providers.json" "resources/$org/.vapi-credential-providers.json"; fi
272274
# This machine's baselines and snapshots. They are not in git, so everyone
273275
# who has pulled or pushed since the move runs these two on their machine.
274276
if [ -d "state/$org/local/baselines" ]; then mkdir -p .vapi-state-hash && mv "state/$org/local/baselines" ".vapi-state-hash/$org"; fi

‎docs/guides/configuration.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ These are hand-written. The files the engine writes live apart from them, in
5959
| --- | --- |
6060
| `state/<org>/state.json` | Which platform resource (UUID) each file under `resources/<org>/` is. |
6161
| `state/<org>/org.json` | The Vapi org ID the folder belongs to. Written by the first command that can see the key's org, then checked by every command before any request: a key for another org stops the command. If a folder genuinely moves to another org, delete the file in a reviewed commit. |
62-
| `state/<org>/credential-providers.json` | The provider of each saved credential, by name. Written by every pull and committed with the state file. It holds no secret. The credential-pin check reads it. |
62+
| `state/<org>/credential-providers.json` | The provider of each saved credential, by name. Written by every pull and committed with the state file. It holds no secret. The credential-pin check reads it. While an org's state is in the older layout it is `resources/<org>/.vapi-credential-providers.json`. |
6363

6464
## Other environment variables
6565

‎docs/guides/credential-pins.md‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,12 @@ including `npm run pull -- <org> --bootstrap`, which changes no resource
130130
file. If the file is missing or older than the state file, the check reports
131131
`credential-pin-unchecked` and asks for that pull.
132132

133+
In a repository whose state is still in the layout from before `state/`, the
134+
file is `resources/<org>/.vapi-credential-providers.json` instead, which the
135+
commit step that repository already has stages with the folder. `npm run
136+
migrate` moves it with the rest: see
137+
[Upgrading from an older version](commands.md#upgrading-from-an-older-version).
138+
133139
Give every key a name in Vapi before the first pull. Two keys with no name
134140
and the same provider get the same name here, and only one is kept. Pull
135141
warns when that happens.

‎improvements.md‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2196,7 +2196,9 @@ itself customer-keys-only so the report is an error there.
21962196
### Status
21972197

21982198
**RESOLVED 2026-11-17.** Pull writes
2199-
`state/<org>/credential-providers.json` and warns when two
2199+
`state/<org>/credential-providers.json`
2200+
(`resources/<org>/.vapi-credential-providers.json` while the org's state is
2201+
in the older layout) and warns when two
22002202
credentials collide on one name. `validate` has the
22012203
`credential-pin-hides-key` rule, an error in an org whose
22022204
`.vapi-policy.yml` sets `customerKeysOnly: true`. The promotion plan warns

‎src/credential-kinds.ts‎

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,23 @@
1010
// Config-free so validate, push and tests can read any org.
1111

1212
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
13-
import { dirname, join } from "node:path";
14-
import { stateOrgDir } from "./state-paths.ts";
13+
import { dirname, relative } from "node:path";
14+
import { stateRecordPath } from "./state-paths.ts";
1515
import { sortedKeysReplacer } from "./state-serialize.ts";
1616

17+
// state/<org>/credential-providers.json, or
18+
// resources/<org>/.vapi-credential-providers.json while the org's state is
19+
// still in the old layout, where an older commit step stages it.
1720
export function credentialKindsPath(rootDir: string, org: string): string {
18-
return join(stateOrgDir(rootDir, org), "credential-providers.json");
21+
return stateRecordPath(rootDir, org, "credential-providers");
1922
}
2023

2124
/** The file as a person names it: its path from the repository root. */
22-
export function credentialKindsLabel(org: string): string {
23-
return `state/${org}/credential-providers.json`;
25+
export function credentialKindsLabel(rootDir: string, org: string): string {
26+
return relative(rootDir, credentialKindsPath(rootDir, org)).replaceAll(
27+
"\\",
28+
"/",
29+
);
2430
}
2531

2632
export interface CredentialKind {

‎src/push.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,10 @@ const RESOURCE_LABEL_TO_TYPE: Record<string, ResourceType> = {
6161
"simulation suite": "simulationSuites",
6262
};
6363

64-
import { credentialKindsRead } from "./credential-kinds.ts";
64+
import {
65+
credentialKindsLabel,
66+
credentialKindsRead,
67+
} from "./credential-kinds.ts";
6568
import {
6669
credentialForwardMap,
6770
credentialReverseMap,
@@ -1798,6 +1801,7 @@ async function main(): Promise<void> {
17981801
org: VAPI_ENV,
17991802
state,
18001803
kinds: credentialKindsRead(BASE_DIR, VAPI_ENV),
1804+
kindsFile: credentialKindsLabel(BASE_DIR, VAPI_ENV),
18011805
customerKeysOnly: orgPolicyRead(RESOURCES_DIR).customerKeysOnly,
18021806
}),
18031807
];

‎src/state-paths.ts‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
//
33
// state/<org>/state.json resource name → Vapi UUID (committed)
44
// state/<org>/org.json the Vapi org this folder is pinned to (committed)
5+
// state/<org>/<record>.json what the engine records beside them (committed)
56
// state/<org>/local/baselines/ drift baselines, one file per UUID (this machine only)
67
// state/<org>/local/snapshots/ push snapshots for rollback (this machine only)
78
// state/commit-step.json a person's word that their commit step stages state/ (committed)
@@ -184,6 +185,41 @@ export function orgPinFileRead(rootDir: string, org: string): string {
184185
/** The org pin to write: the one that is read. */
185186
export const orgPinFileWrite = orgPinFileRead;
186187

188+
/** The records the engine keeps beside an org's state file, by name. */
189+
export const STATE_RECORDS = ["credential-providers"] as const;
190+
export type StateRecord = (typeof STATE_RECORDS)[number];
191+
192+
function recordPath(rootDir: string, org: string, name: StateRecord): string {
193+
return join(stateOrgDir(rootDir, org), `${name}.json`);
194+
}
195+
196+
function recordLegacyPath(
197+
rootDir: string,
198+
org: string,
199+
name: StateRecord,
200+
): string {
201+
return join(rootDir, "resources", org, `.vapi-${name}.json`);
202+
}
203+
204+
/**
205+
* A record the engine keeps beside the state file: where it is, else where
206+
* its first write goes. For an org in the old layout that is
207+
* resources/<org>/.vapi-<name>.json, beside the old org pin, which a commit
208+
* step from before state/ already stages with the folder.
209+
*/
210+
export function stateRecordPath(
211+
rootDir: string,
212+
org: string,
213+
name: StateRecord,
214+
): string {
215+
return fileInLayout(
216+
recordPath(rootDir, org, name),
217+
recordLegacyPath(rootDir, org, name),
218+
rootDir,
219+
org,
220+
);
221+
}
222+
187223
/** The state file as a person names it: its path from the repository root. */
188224
export function stateFileLabel(rootDir: string, org: string): string {
189225
return relative(rootDir, stateFileRead(rootDir, org)).replaceAll("\\", "/");
@@ -237,6 +273,12 @@ function committedFiles(rootDir: string, org: string): CommittedFile[] {
237273
legacyLabel: `resources/${org}/.vapi-org.json`,
238274
nextLabel: `${STATE_DIR}/${org}/org.json`,
239275
},
276+
...STATE_RECORDS.map((name) => ({
277+
legacy: recordLegacyPath(rootDir, org, name),
278+
next: recordPath(rootDir, org, name),
279+
legacyLabel: `resources/${org}/.vapi-${name}.json`,
280+
nextLabel: `${STATE_DIR}/${org}/${name}.json`,
281+
})),
240282
];
241283
}
242284

‎src/validate-cmd.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@ import {
1414
RESOURCES_DIR,
1515
VAPI_ENV,
1616
} from "./config.ts";
17-
import { credentialKindsRead } from "./credential-kinds.ts";
17+
import {
18+
credentialKindsLabel,
19+
credentialKindsRead,
20+
} from "./credential-kinds.ts";
1821
import { orgPolicyRead } from "./org-policy.ts";
1922
import { loadResources } from "./resources.ts";
2023
import { createEmptyState, loadState } from "./state.ts";
@@ -78,6 +81,7 @@ async function main(): Promise<void> {
7881
org: VAPI_ENV,
7982
state,
8083
kinds: credentialKindsRead(BASE_DIR, VAPI_ENV),
84+
kindsFile: credentialKindsLabel(BASE_DIR, VAPI_ENV),
8185
customerKeysOnly: policy.customerKeysOnly,
8286
}),
8387
];

‎src/validate-credential-pins.ts‎

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,7 @@
1616
// the org is customer-keys-only (a finding is then an error, else a warning).
1717
// ─────────────────────────────────────────────────────────────────────────────
1818

19-
import {
20-
type CredentialKinds,
21-
credentialKindsLabel,
22-
} from "./credential-kinds.ts";
19+
import type { CredentialKinds } from "./credential-kinds.ts";
2320
import { credentialReverseMap } from "./credentials.ts";
2421
import { referencesCollect } from "./resolver.ts";
2522
import type { LoadedResources, ResourceType, StateFile } from "./types.ts";
@@ -152,9 +149,11 @@ export function validateCredentialPins(args: {
152149
// What each saved credential is a key for; undefined before the first pull
153150
// that recorded it.
154151
kinds: CredentialKinds | undefined;
152+
// The file the kinds are read from, as a person names it.
153+
kindsFile: string;
155154
customerKeysOnly: boolean;
156155
}): ValidationFinding[] {
157-
const { loaded, org, state, kinds, customerKeysOnly } = args;
156+
const { loaded, org, state, kinds, kindsFile, customerKeysOnly } = args;
158157
const severity = customerKeysOnly ? "error" : "warn";
159158
const uuidToName = credentialReverseMap(state);
160159
const nameOf = (ref: string) => uuidToName.get(ref) ?? ref;
@@ -263,7 +262,7 @@ export function validateCredentialPins(args: {
263262
else if (!kindsReported)
264263
finding(
265264
"credential-pin-unchecked",
266-
`${credentialKindsLabel(org)} ` +
265+
`${kindsFile} ` +
267266
(kinds
268267
? `has no entry for ${quoted(missingKinds)}`
269268
: "doesn't exist yet") +

‎state/README.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,6 @@ Everything under `resources/<org>/`, including `resources/<org>/.vapi-ignore` an
2727

2828
The same files used to sit elsewhere: `.vapi-state.<org>.json` and `.vapi-state.<org>.snapshots/` at the repository root, `.vapi-state-hash/<org>/`, and `resources/<org>/.vapi-org.json`. The engine keeps reading and writing them there, on your machine and in CI, for as long as you leave them.
2929

30+
While an org's state is there, the engine writes its credential providers record to `resources/<org>/.vapi-credential-providers.json`, where the commit step such a repository already has stages it.
31+
3032
Only `npm run migrate` moves them here. Before it moves anything it says what the step that commits state after a run has to stage, and it moves nothing while it can't see that step stage this folder, unless you tell it yours does. Commit the removal of the old files together with the new folder. See [Upgrading from an older version](../docs/guides/commands.md#upgrading-from-an-older-version).

0 commit comments

Comments
 (0)