Skip to content

Commit bc80d57

Browse files
refactor(validate): keep the credential providers record in state/<org>/
The record is written by pull, so it belongs with the rest of the engine's files. The hand-written .vapi-policy.yml stays in resources/<org>/. Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
1 parent 83770b0 commit bc80d57

12 files changed

Lines changed: 43 additions & 30 deletions

‎docs/guides/credential-pins.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ a key for every provider it uses.
115115

116116
The state file maps a credential's name to its UUID and nothing else. Pull
117117
also records each key's provider in
118-
`resources/<org>/.vapi-credential-providers.json`:
118+
`state/<org>/credential-providers.json`:
119119

120120
```json
121121
{

‎docs/guides/how-it-works.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ Credentials are managed automatically through the state file. No secrets in reso
116116
3. **Push** resolves names back to UUIDs before sending to the API
117117

118118
Pull also records each credential's provider in
119-
`resources/<org>/.vapi-credential-providers.json`, so `validate` can check a
119+
`state/<org>/credential-providers.json`, so `validate` can check a
120120
`credentialIds` list against the keys the org has: see
121121
[Credential pins](credential-pins.md).
122122

‎improvements.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ you which stack PR closes the row.**
9191
| 37 | Resource validation ran only at deploy time, after merge | A config `apply` refuses could merge and block deploys and promotion | #32 | RESOLVED 2026-10-03 (#76) |
9292
| 38 | Promotion can't carry a simulation that uses a stock personality by UUID | Gated orgs, and any promoted tests, need local personality files | None | Open |
9393
| 39 | Engine state looked like temp files and sat in three places | Deleting the state file makes the next push duplicate every resource | None | RESOLVED 2026-11-17 (#97) |
94+
| 40 | Nothing checked a `credentialIds` list against the keys an org has saved | A list that hides the org's own key runs the call on Vapi's key, silently | None | RESOLVED 2026-11-17 (#96) |
9495

9596
**Active backlog after cleanup:** `#2`, `#6`, `#8`, `#12`, `#20`, `#24–#26`, `#31`, and the open remainder of `#27` (wiring the listing-completeness verdict into push/delete/audit, and moving `cleanup.ts` onto the shared pager). Resolved entries stay in this file as historical incident notes per the maintenance directive; stale superseded backlog rows are not duplicated.
9697

@@ -2168,7 +2169,7 @@ itself customer-keys-only so the report is an error there.
21682169
### Status
21692170

21702171
**RESOLVED 2026-11-17.** Pull writes
2171-
`resources/<org>/.vapi-credential-providers.json` and warns when two
2172+
`state/<org>/credential-providers.json` and warns when two
21722173
credentials collide on one name. `validate` has the
21732174
`credential-pin-hides-key` rule, an error in an org whose
21742175
`.vapi-policy.yml` sets `customerKeysOnly: true`. The promotion plan warns

‎src/credential-kinds.ts‎

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,25 @@
33
// The state file maps a credential's name to its UUID and nothing else. A
44
// `credentialIds` list can only be checked against the org's keys when the
55
// provider of each key is known too, and pull already fetches that. Pull
6-
// records it in resources/<org>/.vapi-credential-providers.json, which is
7-
// committed with the folder. It holds no secret: a provider name per key,
8-
// and whether a storage bucket is set on it.
6+
// records it in state/<org>/credential-providers.json, which is committed
7+
// with the state file. It holds no secret: a provider name per key, and
8+
// whether a storage bucket is set on it.
99
//
1010
// Config-free so validate, push and tests can read any org.
1111

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

16-
export const CREDENTIAL_KINDS_FILE = ".vapi-credential-providers.json";
17+
export function credentialKindsPath(rootDir: string, org: string): string {
18+
return join(stateOrgDir(rootDir, org), "credential-providers.json");
19+
}
20+
21+
/** 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`;
24+
}
1725

1826
export interface CredentialKind {
1927
provider: string;
@@ -46,9 +54,10 @@ export function credentialKindOf(
4654

4755
/** The org's recorded credential kinds, or undefined before its first pull. */
4856
export function credentialKindsRead(
49-
resourcesDir: string,
57+
rootDir: string,
58+
org: string,
5059
): CredentialKinds | undefined {
51-
const path = join(resourcesDir, CREDENTIAL_KINDS_FILE);
60+
const path = credentialKindsPath(rootDir, org);
5261
if (!existsSync(path)) return undefined;
5362
const raw = record(JSON.parse(readFileSync(path, "utf-8")));
5463
if (!raw) throw new Error(`${path} must hold a JSON object`);
@@ -66,13 +75,14 @@ export function credentialKindsRead(
6675

6776
/** Write the org's credential kinds. Returns false when nothing changed. */
6877
export function credentialKindsWrite(
69-
resourcesDir: string,
78+
rootDir: string,
79+
org: string,
7080
kinds: CredentialKinds,
7181
): boolean {
72-
const path = join(resourcesDir, CREDENTIAL_KINDS_FILE);
82+
const path = credentialKindsPath(rootDir, org);
7383
const content = `${JSON.stringify(kinds, sortedKeysReplacer, 2)}\n`;
7484
if (existsSync(path) && readFileSync(path, "utf-8") === content) return false;
75-
mkdirSync(resourcesDir, { recursive: true });
85+
mkdirSync(dirname(path), { recursive: true });
7686
writeFileSync(path, content);
7787
return true;
7888
}

‎src/pull.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ async function pullCredentials(state: StateFile): Promise<void> {
370370
state.credentials = newSection;
371371
// The state file stays a name → UUID map. What each key is for goes in a
372372
// file of its own, which the credential-pin check reads.
373-
credentialKindsWrite(RESOURCES_DIR, kinds);
373+
credentialKindsWrite(BASE_DIR, VAPI_ENV, kinds);
374374
}
375375

376376
// ─────────────────────────────────────────────────────────────────────────────

‎src/push.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1797,7 +1797,7 @@ async function main(): Promise<void> {
17971797
loaded: loadedResources,
17981798
org: VAPI_ENV,
17991799
state,
1800-
kinds: credentialKindsRead(RESOURCES_DIR),
1800+
kinds: credentialKindsRead(BASE_DIR, VAPI_ENV),
18011801
customerKeysOnly: orgPolicyRead(RESOURCES_DIR).customerKeysOnly,
18021802
}),
18031803
];

‎src/validate-cmd.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ async function main(): Promise<void> {
7777
loaded: resources,
7878
org: VAPI_ENV,
7979
state,
80-
kinds: credentialKindsRead(RESOURCES_DIR),
80+
kinds: credentialKindsRead(BASE_DIR, VAPI_ENV),
8181
customerKeysOnly: policy.customerKeysOnly,
8282
}),
8383
];

‎src/validate-credential-pins.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
// ─────────────────────────────────────────────────────────────────────────────
1818

1919
import {
20-
CREDENTIAL_KINDS_FILE,
2120
type CredentialKinds,
21+
credentialKindsLabel,
2222
} from "./credential-kinds.ts";
2323
import { credentialReverseMap } from "./credentials.ts";
2424
import { referencesCollect } from "./resolver.ts";
@@ -263,7 +263,7 @@ export function validateCredentialPins(args: {
263263
else if (!kindsReported)
264264
finding(
265265
"credential-pin-unchecked",
266-
`resources/${org}/${CREDENTIAL_KINDS_FILE} ` +
266+
`${credentialKindsLabel(org)} ` +
267267
(kinds
268268
? `has no entry for ${quoted(missingKinds)}`
269269
: "doesn't exist yet") +

‎state/README.md‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,20 @@ The engine writes everything in this folder. Don't edit or delete these files by
66
| --- | --- | --- |
77
| `state/<org>/state.json` | Which Vapi resource (UUID) each file under `resources/<org>/` is. | Yes |
88
| `state/<org>/org.json` | The Vapi org that `resources/<org>/` belongs to. A command run with another org's key stops before it reads or changes anything. | Yes |
9+
| `state/<org>/credential-providers.json` | The provider of each saved credential, by name, with no secret. The [credential-pin check](../docs/guides/credential-pins.md) reads it. | Yes |
910
| `state/<org>/local/baselines/` | The last version of each resource this machine saw on the platform, used to notice dashboard edits. | No |
1011
| `state/<org>/local/snapshots/` | A copy of each resource taken before a push, for `npm run rollback`. | No |
1112

1213
## What happens if a file goes missing
1314

1415
- **`state.json`**: the engine no longer knows which resources already exist, so the next push creates every one of them again as a duplicate. Restore the file from git (`git checkout -- state/<org>/state.json`). Never rebuild it by hand.
1516
- **`org.json`**: the next command pins the folder again to whichever org its key belongs to, so the protection against a wrong key is gone until then. Restore it from git.
17+
- **`credential-providers.json`**: `validate` can't check `credentialIds` lists and says so. The next pull writes the file again.
1618
- **`local/`**: nothing breaks. The next pull records new baselines. Snapshots taken so far are gone, so there is nothing to roll back to until the next push.
1719

1820
## What is yours to edit
1921

20-
Everything under `resources/<org>/`, including `resources/<org>/.vapi-ignore`, is hand-written and yours. This folder is the engine's.
22+
Everything under `resources/<org>/`, including `resources/<org>/.vapi-ignore` and `resources/<org>/.vapi-policy.yml`, is hand-written and yours. This folder is the engine's.
2123

2224
## Repositories created before this folder existed
2325

‎tests/credential-kinds.test.ts‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { tmpdir } from "node:os";
44
import { join } from "node:path";
55
import test from "node:test";
66
import {
7-
CREDENTIAL_KINDS_FILE,
87
credentialKindOf,
98
credentialKindsRead,
109
credentialKindsWrite,
@@ -36,14 +35,15 @@ test("a credential's kind is its provider, and whether a bucket is set", () => {
3635
test("the kinds file round-trips, holds nothing else, and isn't rewritten unchanged", () => {
3736
const dir = mkdtempSync(join(tmpdir(), "vapi-kinds-"));
3837
try {
39-
assert.equal(credentialKindsRead(dir), undefined);
38+
assert.equal(credentialKindsRead(dir, "clinic"), undefined);
4039
const kinds = {
4140
recordings: { provider: "azure", bucket: true as const },
4241
elevenlabs: { provider: "11labs" },
4342
};
44-
assert.equal(credentialKindsWrite(dir, kinds), true);
43+
assert.equal(credentialKindsWrite(dir, "clinic", kinds), true);
44+
const file = join(dir, "state/clinic/credential-providers.json");
4545
assert.equal(
46-
readFileSync(join(dir, CREDENTIAL_KINDS_FILE), "utf-8"),
46+
readFileSync(file, "utf-8"),
4747
`{
4848
"elevenlabs": {
4949
"provider": "11labs"
@@ -55,10 +55,10 @@ test("the kinds file round-trips, holds nothing else, and isn't rewritten unchan
5555
}
5656
`,
5757
);
58-
assert.deepEqual(credentialKindsRead(dir), kinds);
59-
const written = statSync(join(dir, CREDENTIAL_KINDS_FILE)).mtimeMs;
60-
assert.equal(credentialKindsWrite(dir, kinds), false);
61-
assert.equal(statSync(join(dir, CREDENTIAL_KINDS_FILE)).mtimeMs, written);
58+
assert.deepEqual(credentialKindsRead(dir, "clinic"), kinds);
59+
const written = statSync(file).mtimeMs;
60+
assert.equal(credentialKindsWrite(dir, "clinic", kinds), false);
61+
assert.equal(statSync(file).mtimeMs, written);
6262
} finally {
6363
rmSync(dir, { recursive: true, force: true });
6464
}

0 commit comments

Comments
 (0)