Skip to content
Closed
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
32 changes: 32 additions & 0 deletions cli/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -478,10 +478,42 @@ export function readConfigOrgId(path: string): string | undefined {
}
}

const VALID_TOP_LEVEL_KEYS: ReadonlySet<string> = new Set([
"contract",
"orgId",
"publicUrl",
"apiUrl",
"target",
"model",
"modelProvider",
"basePort",
"services",
"plugins",
"skills",
"env",
"secretEnv",
"securityScreen",
"vms",
"imageOverrides",
"sandbox",
"appPrefix",
"region",
"flyOrg",
"imageFrom",
"deployAppPrefix",
"aws",
]);

function validate(raw: unknown, path: string): QmConfig {
if (!isPlainObject(raw)) throw new CliError(`${path}: expected a JSON object`);
const o = raw;

for (const key of Object.keys(o)) {
if (!VALID_TOP_LEVEL_KEYS.has(key)) {
throw new CliError(`${path}: unknown top-level field ${JSON.stringify(key)}`);
}
}

const contract = o["contract"];
if (contract !== CONTRACT_VERSION) {
if (typeof contract === "number" && Number.isInteger(contract)) {
Expand Down
6 changes: 6 additions & 0 deletions cli/test/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ test("required fields: orgId, target, services (must include core), valid servic
const { config } = loadConfigAt(path);
assert.deepEqual(config.services, ["core", "web-ui", "admin", "portal"]);
});
withConfig({ unknownField: "bad" }, ({ path }) =>
assert.throws(() => loadConfigAt(path), /unknown top-level field "unknownField"/),
);
withConfig({ org_id: "acme" }, ({ path }) =>
assert.throws(() => loadConfigAt(path), /unknown top-level field "org_id"/),
);
});

test("apiUrl must be an http(s) origin URL; the trailing slash is stripped", () => {
Expand Down