From 0d52eab5a0e522e03b942a43f5e19852b2932d57 Mon Sep 17 00:00:00 2001 From: Danyang Chen Date: Wed, 2 Dec 2026 12:53:26 +0800 Subject: [PATCH] runtime/flybot-image: keep the model-api recipe test off the host secret store The model-api test asserted that resolveModelApiPath({}) and loadModelApi({}) are undefined, which only holds on a host without a provisioned model-api file. On a configured host the default candidate list finds the real /run/secrets file, both assertions fail, and the recipe suite can never be green there while CI stays green because the runner has no such file. Take the default candidate list as an optional second argument, pass an explicit empty list from the test, and assert that every default candidate lives under an allowed prefix. Production callers keep the single-argument form, so the default resolution path is unchanged. Refs #3490 --- runtime/flybot-image/model-api.js | 10 +++++----- runtime/flybot-image/test/model-api.test.js | 13 ++++++++++--- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/runtime/flybot-image/model-api.js b/runtime/flybot-image/model-api.js index 17022e058..af5f0175b 100644 --- a/runtime/flybot-image/model-api.js +++ b/runtime/flybot-image/model-api.js @@ -11,7 +11,7 @@ export const DEFAULT_FILES = [ '/data/secrets/model-api.json', ] export const ENV_FILE = 'FLYBOT_WORKSPACE_MODEL_API_FILE' -const ALLOWED_PREFIXES = ['/run/secrets/', '/data/secrets/'] +export const ALLOWED_PREFIXES = ['/run/secrets/', '/data/secrets/'] const MAX_BYTES = 16 * 1024 const PROVIDER = /^[a-z0-9][a-z0-9-]{0,63}$/ const MODEL = /^[A-Za-z0-9._:/-]{1,128}$/ @@ -123,10 +123,10 @@ export function readModelApiFile(path) { return contentsToModelApi(readFileSync(assertAllowedPath(path), 'utf8')) } -export function resolveModelApiPath(env = process.env) { +export function resolveModelApiPath(env = process.env, defaults = DEFAULT_FILES) { const configured = env[ENV_FILE] if (configured && configured.trim() !== '') return configured.trim() - for (const candidate of DEFAULT_FILES) { + for (const candidate of defaults) { try { statSync(candidate) return candidate @@ -135,8 +135,8 @@ export function resolveModelApiPath(env = process.env) { return undefined } -export function loadModelApi(env = process.env) { - const path = resolveModelApiPath(env) +export function loadModelApi(env = process.env, defaults = DEFAULT_FILES) { + const path = resolveModelApiPath(env, defaults) if (path === undefined) return undefined return readModelApiFile(path) } diff --git a/runtime/flybot-image/test/model-api.test.js b/runtime/flybot-image/test/model-api.test.js index 270bc8e6a..817aa781e 100644 --- a/runtime/flybot-image/test/model-api.test.js +++ b/runtime/flybot-image/test/model-api.test.js @@ -3,7 +3,7 @@ import { mkdtempSync, mkdirSync, writeFileSync, symlinkSync, chmodSync, rmSync } import { tmpdir } from 'node:os' import { dirname, join } from 'node:path' import { test } from 'node:test' -import { applyModelApi, contentsToModelApi, keyRefFor, loadModelApi, parseModelApi, readModelApiFile, redact, resolveModelApiPath, ModelApiError } from '../model-api.js' +import { ALLOWED_PREFIXES, applyModelApi, contentsToModelApi, DEFAULT_FILES, keyRefFor, loadModelApi, parseModelApi, readModelApiFile, redact, resolveModelApiPath, ModelApiError } from '../model-api.js' const sample = { provider: 'deepseek', @@ -77,8 +77,15 @@ test('reads only allowlisted secret paths and skips a missing file', () => { const sneaky = join(secrets, 'link.json') symlinkSync(outside, sneaky) assert.throws(() => readModelApiFile(sneaky), ModelApiError) - assert.equal(resolveModelApiPath({}), undefined) - assert.equal(loadModelApi({}), undefined) + // The default file list is host state, not recipe state: a provisioned host + // really does have /run/secrets/flybot-workspace-model-api.json. Pass an + // explicit empty list so this test stays hermetic, then check the defaults + // themselves are allowlisted. + assert.equal(resolveModelApiPath({}, []), undefined) + assert.equal(loadModelApi({}, []), undefined) + for (const path of DEFAULT_FILES) { + assert.ok(ALLOWED_PREFIXES.some((prefix) => path.startsWith(prefix)), `${path} must live under an allowlisted secret directory`) + } rmSync(root, { recursive: true, force: true }) })