@vellumai/credential-executor 0.11.7-dev.202608272311.f90ed23 → 0.11.7-dev.202608281503.cbafd6c
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import { mkdtempSync } from "node:fs";
|
|
1
|
+
import { existsSync, mkdirSync, mkdtempSync, writeFileSync } from "node:fs";
|
|
2
2
|
import { tmpdir } from "node:os";
|
|
3
3
|
import { join } from "node:path";
|
|
4
4
|
|
|
5
5
|
import { describe, expect, test } from "bun:test";
|
|
6
6
|
|
|
7
|
+
import type { SecureKeyBackend } from "@vellumai/credential-storage";
|
|
7
8
|
import type { CredentialRecord } from "@vellumai/service-contracts/credential-rpc";
|
|
8
9
|
|
|
10
|
+
import { importWorkspaceMetadataMigration } from "../migrations/003-import-workspace-metadata.js";
|
|
9
11
|
import {
|
|
10
12
|
CesMetadataStore,
|
|
11
13
|
getMetadataPath,
|
|
@@ -89,3 +91,122 @@ describe("parseCredentialAccount", () => {
|
|
|
89
91
|
expect(parseCredentialAccount("oauth/google/access")).toBeUndefined();
|
|
90
92
|
});
|
|
91
93
|
});
|
|
94
|
+
|
|
95
|
+
describe("003-import-workspace-metadata", () => {
|
|
96
|
+
test("imports leftover workspace metadata without deleting the file", async () => {
|
|
97
|
+
const workspace = mkdtempSync(join(tmpdir(), "ces-ws-"));
|
|
98
|
+
const cesData = mkdtempSync(join(tmpdir(), "ces-data-"));
|
|
99
|
+
const leftoverPath = join(workspace, "data", "credentials", "metadata.json");
|
|
100
|
+
mkdirSync(join(workspace, "data", "credentials"), { recursive: true });
|
|
101
|
+
writeFileSync(
|
|
102
|
+
leftoverPath,
|
|
103
|
+
JSON.stringify({
|
|
104
|
+
version: 5,
|
|
105
|
+
credentials: [
|
|
106
|
+
makeRecord("vercel", "api_token", { allowedTools: ["publish_page"] }),
|
|
107
|
+
],
|
|
108
|
+
}),
|
|
109
|
+
);
|
|
110
|
+
|
|
111
|
+
const prevWorkspace = process.env.VELLUM_WORKSPACE_DIR;
|
|
112
|
+
const prevMode = process.env.CES_MODE;
|
|
113
|
+
const prevData = process.env.CES_DATA_DIR;
|
|
114
|
+
process.env.VELLUM_WORKSPACE_DIR = workspace;
|
|
115
|
+
process.env.CES_MODE = "managed";
|
|
116
|
+
process.env.CES_DATA_DIR = cesData;
|
|
117
|
+
|
|
118
|
+
const unusedBackend: SecureKeyBackend = {
|
|
119
|
+
get: async () => undefined,
|
|
120
|
+
set: async () => true,
|
|
121
|
+
delete: async () => "not-found",
|
|
122
|
+
list: async () => [],
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
try {
|
|
126
|
+
await importWorkspaceMetadataMigration.run(unusedBackend);
|
|
127
|
+
const store = new CesMetadataStore(getMetadataPath(cesData));
|
|
128
|
+
const imported = store.getByAccount("credential/vercel/api_token");
|
|
129
|
+
expect(imported?.allowedTools).toEqual(["publish_page"]);
|
|
130
|
+
expect(imported?.credentialId).toBe("id-vercel-api_token");
|
|
131
|
+
expect(existsSync(leftoverPath)).toBe(true);
|
|
132
|
+
} finally {
|
|
133
|
+
if (prevWorkspace === undefined) {
|
|
134
|
+
delete process.env.VELLUM_WORKSPACE_DIR;
|
|
135
|
+
} else {
|
|
136
|
+
process.env.VELLUM_WORKSPACE_DIR = prevWorkspace;
|
|
137
|
+
}
|
|
138
|
+
if (prevMode === undefined) {
|
|
139
|
+
delete process.env.CES_MODE;
|
|
140
|
+
} else {
|
|
141
|
+
process.env.CES_MODE = prevMode;
|
|
142
|
+
}
|
|
143
|
+
if (prevData === undefined) {
|
|
144
|
+
delete process.env.CES_DATA_DIR;
|
|
145
|
+
} else {
|
|
146
|
+
process.env.CES_DATA_DIR = prevData;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
test("keeps an existing CES record instead of overwriting it", async () => {
|
|
152
|
+
const workspace = mkdtempSync(join(tmpdir(), "ces-ws-"));
|
|
153
|
+
const cesData = mkdtempSync(join(tmpdir(), "ces-data-"));
|
|
154
|
+
const leftoverPath = join(workspace, "data", "credentials", "metadata.json");
|
|
155
|
+
mkdirSync(join(workspace, "data", "credentials"), { recursive: true });
|
|
156
|
+
writeFileSync(
|
|
157
|
+
leftoverPath,
|
|
158
|
+
JSON.stringify({
|
|
159
|
+
version: 5,
|
|
160
|
+
credentials: [
|
|
161
|
+
makeRecord("vercel", "api_token", { allowedTools: ["bash"] }),
|
|
162
|
+
],
|
|
163
|
+
}),
|
|
164
|
+
);
|
|
165
|
+
const store = new CesMetadataStore(getMetadataPath(cesData));
|
|
166
|
+
store.setByAccount(
|
|
167
|
+
"credential/vercel/api_token",
|
|
168
|
+
makeRecord("vercel", "api_token", {
|
|
169
|
+
credentialId: "id-ces-newer",
|
|
170
|
+
allowedTools: ["publish_page"],
|
|
171
|
+
}),
|
|
172
|
+
);
|
|
173
|
+
|
|
174
|
+
const prevWorkspace = process.env.VELLUM_WORKSPACE_DIR;
|
|
175
|
+
const prevMode = process.env.CES_MODE;
|
|
176
|
+
const prevData = process.env.CES_DATA_DIR;
|
|
177
|
+
process.env.VELLUM_WORKSPACE_DIR = workspace;
|
|
178
|
+
process.env.CES_MODE = "managed";
|
|
179
|
+
process.env.CES_DATA_DIR = cesData;
|
|
180
|
+
|
|
181
|
+
const unusedBackend: SecureKeyBackend = {
|
|
182
|
+
get: async () => undefined,
|
|
183
|
+
set: async () => true,
|
|
184
|
+
delete: async () => "not-found",
|
|
185
|
+
list: async () => [],
|
|
186
|
+
};
|
|
187
|
+
|
|
188
|
+
try {
|
|
189
|
+
await importWorkspaceMetadataMigration.run(unusedBackend);
|
|
190
|
+
const kept = store.getByAccount("credential/vercel/api_token");
|
|
191
|
+
expect(kept?.credentialId).toBe("id-ces-newer");
|
|
192
|
+
expect(kept?.allowedTools).toEqual(["publish_page"]);
|
|
193
|
+
expect(existsSync(leftoverPath)).toBe(true);
|
|
194
|
+
} finally {
|
|
195
|
+
if (prevWorkspace === undefined) {
|
|
196
|
+
delete process.env.VELLUM_WORKSPACE_DIR;
|
|
197
|
+
} else {
|
|
198
|
+
process.env.VELLUM_WORKSPACE_DIR = prevWorkspace;
|
|
199
|
+
}
|
|
200
|
+
if (prevMode === undefined) {
|
|
201
|
+
delete process.env.CES_MODE;
|
|
202
|
+
} else {
|
|
203
|
+
process.env.CES_MODE = prevMode;
|
|
204
|
+
}
|
|
205
|
+
if (prevData === undefined) {
|
|
206
|
+
delete process.env.CES_DATA_DIR;
|
|
207
|
+
} else {
|
|
208
|
+
process.env.CES_DATA_DIR = prevData;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
});
|
|
212
|
+
});
|
|
@@ -177,6 +177,7 @@ export async function handleLogExportRoute(
|
|
|
177
177
|
const proc = spawnSync("tar", ["czf", "-", "-C", staging, "."], {
|
|
178
178
|
maxBuffer: MAX_LOG_BYTES * 2, // allow headroom for tar overhead
|
|
179
179
|
timeout: 30_000,
|
|
180
|
+
windowsHide: true,
|
|
180
181
|
});
|
|
181
182
|
|
|
182
183
|
if (proc.status !== 0) {
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
|
|
4
|
+
import type { SecureKeyBackend } from "@vellumai/credential-storage";
|
|
5
|
+
|
|
6
|
+
import { getLogger } from "../logger.js";
|
|
7
|
+
import { getCesDataRoot } from "../paths.js";
|
|
8
|
+
import {
|
|
9
|
+
accountForRecord,
|
|
10
|
+
CesMetadataStore,
|
|
11
|
+
getMetadataPath,
|
|
12
|
+
} from "../records/metadata-store.js";
|
|
13
|
+
import type { CesMigration } from "./types.js";
|
|
14
|
+
|
|
15
|
+
function leftoverWorkspaceMetadataPath(
|
|
16
|
+
workspaceDir: string | undefined,
|
|
17
|
+
): string | undefined {
|
|
18
|
+
if (!workspaceDir || workspaceDir.trim() === "") {
|
|
19
|
+
return undefined;
|
|
20
|
+
}
|
|
21
|
+
return join(workspaceDir, "data", "credentials", "metadata.json");
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const log = getLogger("ces-migrations");
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Copy workspace `metadata.json` catalog rows into the CES metadata store.
|
|
28
|
+
*
|
|
29
|
+
* CES does not delete the workspace file (the workspace volume is
|
|
30
|
+
* read-only in managed mode).
|
|
31
|
+
*/
|
|
32
|
+
export const importWorkspaceMetadataMigration: CesMigration = {
|
|
33
|
+
id: "003-import-workspace-metadata",
|
|
34
|
+
description:
|
|
35
|
+
"Import workspace credential metadata.json into the CES metadata store",
|
|
36
|
+
|
|
37
|
+
async run(_backend: SecureKeyBackend): Promise<void> {
|
|
38
|
+
const workspaceDir = process.env["VELLUM_WORKSPACE_DIR"]?.trim();
|
|
39
|
+
const leftoverPath = leftoverWorkspaceMetadataPath(workspaceDir);
|
|
40
|
+
if (!leftoverPath || !existsSync(leftoverPath)) {
|
|
41
|
+
log.info("CES metadata import: no workspace metadata.json; skipping");
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const source = new CesMetadataStore(leftoverPath);
|
|
46
|
+
const records = source.list();
|
|
47
|
+
if (records.length === 0) {
|
|
48
|
+
log.info("CES metadata import: workspace metadata.json has no rows");
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const store = new CesMetadataStore(getMetadataPath(getCesDataRoot()));
|
|
53
|
+
let imported = 0;
|
|
54
|
+
let skipped = 0;
|
|
55
|
+
for (const { record } of records) {
|
|
56
|
+
const account = accountForRecord(record);
|
|
57
|
+
const existing = store.getByAccount(account);
|
|
58
|
+
if (existing) {
|
|
59
|
+
skipped += 1;
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
const ok = store.setByAccount(account, record);
|
|
63
|
+
if (ok) {
|
|
64
|
+
imported += 1;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
log.info(
|
|
68
|
+
{ imported, skipped, total: records.length },
|
|
69
|
+
"CES metadata import from workspace metadata.json complete",
|
|
70
|
+
);
|
|
71
|
+
},
|
|
72
|
+
|
|
73
|
+
async down(_backend: SecureKeyBackend): Promise<void> {
|
|
74
|
+
// Forward-only: records remain in CES.
|
|
75
|
+
},
|
|
76
|
+
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { apiKeyToCredentialsMigration } from "./002-api-keys-to-credentials.js";
|
|
2
1
|
import { noOpMigration } from "./001-no-op.js";
|
|
2
|
+
import { apiKeyToCredentialsMigration } from "./002-api-keys-to-credentials.js";
|
|
3
|
+
import { importWorkspaceMetadataMigration } from "./003-import-workspace-metadata.js";
|
|
3
4
|
import type { CesMigration } from "./types.js";
|
|
4
5
|
|
|
5
6
|
/**
|
|
@@ -12,4 +13,5 @@ import type { CesMigration } from "./types.js";
|
|
|
12
13
|
export const CES_MIGRATIONS: CesMigration[] = [
|
|
13
14
|
noOpMigration,
|
|
14
15
|
apiKeyToCredentialsMigration,
|
|
16
|
+
importWorkspaceMetadataMigration,
|
|
15
17
|
];
|