Skip to content

Commit ac2ad7b

Browse files
authored
fix(cli): load env before validate (#28)
Change-Id: I826a9c0f6f6419b70e1d5fbf3ec1f262d8863151
1 parent c99032a commit ac2ad7b

2 files changed

Lines changed: 33 additions & 3 deletions

File tree

packages/cli/src/commands/validate.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import { resolve } from "node:path";
22
import { resolveProjectConfig, UserError, validateProjectConfig } from "@openagentpack/sdk";
3+
import { ensureCredentials } from "../credentials.ts";
34
import { log } from "../logger.ts";
45

56
export async function validateCommand(options: { file: string }) {
7+
ensureCredentials();
68
const configPath = resolve(options.file);
79
log.info(`Validating ${configPath}...`);
810
const { config } = await resolveProjectConfig(options.file);

packages/cli/tests/unit/cli-contracts.test.ts

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,10 @@ vaults:
113113
return configPath;
114114
}
115115

116-
async function runAgents(args: string[], env: Record<string, string> = {}) {
117-
const proc = Bun.spawn([process.execPath, "run", "bin/agents.ts", ...args], {
118-
cwd: REPO_ROOT,
116+
async function runAgents(args: string[], env: Record<string, string> = {}, cwd = REPO_ROOT) {
117+
const entry = cwd === REPO_ROOT ? "bin/agents.ts" : join(REPO_ROOT, "bin/agents.ts");
118+
const proc = Bun.spawn([process.execPath, "run", entry, ...args], {
119+
cwd,
119120
stdout: "pipe",
120121
stderr: "pipe",
121122
env: {
@@ -430,6 +431,33 @@ test("validate reports reference errors through the core runtime", async () => {
430431
expect(result.stderr).toContain("references unknown environment 'ghost'");
431432
});
432433

434+
test("validate loads .env before resolving provider placeholders", async () => {
435+
const dir = await makeTempDir();
436+
await Bun.write(
437+
join(dir, "agents.yaml"),
438+
`version: "1"
439+
440+
providers:
441+
qoder:
442+
api_key: \${QODER_PAT}
443+
444+
defaults:
445+
provider: qoder
446+
447+
agents:
448+
assistant:
449+
model: ultimate
450+
instructions: "You are helpful."
451+
`,
452+
);
453+
await Bun.write(join(dir, ".env"), "QODER_PAT=test-token\n");
454+
455+
const result = await runAgents(["validate", "--file", "agents.yaml"], { QODER_PAT: "" }, dir);
456+
457+
expect(result.exitCode).toBe(0);
458+
expect(result.stderr).toContain("Configuration is valid");
459+
});
460+
433461
test("models list keeps missing config guidance in the core runtime", async () => {
434462
const result = await runAgents(["models", "list", "--file", "/missing/agents.yaml"]);
435463

0 commit comments

Comments
 (0)