Skip to content

Commit ac16807

Browse files
igorcostaAutohand Evolve
andcommitted
Embed the model catalog in standalone release binaries
Load the baseline catalog as a compile-time asset so clean installations do not depend on repository files or a previously cached remote catalog. Add a compiled-binary regression test that runs with an empty Autohand home outside the checkout. Co-authored-by: Autohand Evolve <code-noreply@autohand.ai>
1 parent cb61cc4 commit ac16807

2 files changed

Lines changed: 65 additions & 1 deletion

File tree

‎src/providers/modelCatalog.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { existsSync, readFileSync } from "node:fs";
88
import { dirname, join, resolve } from "node:path";
99
import { fileURLToPath } from "node:url";
1010
import type { BuiltInProviderName, ReasoningEffort } from "../types.js";
11+
import bundledModelCatalog from "./models.json" with { type: "json" };
1112
import {
1213
getRemoteModelCatalogPath,
1314
getUserModelCatalogPath,
@@ -223,6 +224,10 @@ function readCatalogFile(filePath: string): ModelCatalog {
223224
}
224225
}
225226

227+
function readBundledCatalog(): ModelCatalog {
228+
return normalizeCatalog(bundledModelCatalog);
229+
}
230+
226231
export function mergeModelOptions(
227232
primary: readonly ModelCatalogEntry[],
228233
fallback: readonly ModelCatalogEntry[],
@@ -279,7 +284,7 @@ function mergeCatalogs(base: ModelCatalog, override: ModelCatalog): ModelCatalog
279284
}
280285

281286
export function loadModelCatalog(): ModelCatalog {
282-
const bundled = readCatalogFile(getBundledModelCatalogPath());
287+
const bundled = readBundledCatalog();
283288
const remote = readCatalogFile(getRemoteModelCatalogPath());
284289
const override = readCatalogFile(getUserModelCatalogPath());
285290
return mergeCatalogs(mergeCatalogs(bundled, remote), override);
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/**
2+
* @license
3+
* Copyright 2026 Autohand AI LLC
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
import { execFileSync } from "node:child_process";
8+
import { chmodSync, mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
9+
import { tmpdir } from "node:os";
10+
import { join, resolve } from "node:path";
11+
import { describe, expect, it } from "vitest";
12+
13+
const ROOT = resolve(import.meta.dirname, "../..");
14+
15+
describe("standalone model catalog binary", () => {
16+
it("retains required Autohand AI model metadata outside the repository checkout", () => {
17+
const directory = mkdtempSync(join(tmpdir(), "autohand-catalog-binary-"));
18+
const runDirectory = join(directory, "run");
19+
const autohandHome = join(directory, "autohand-home");
20+
const entryPath = join(directory, "entry.ts");
21+
const binaryPath = join(directory, "catalog-check");
22+
const catalogModulePath = join(ROOT, "src/providers/modelCatalog.ts");
23+
24+
mkdirSync(runDirectory);
25+
mkdirSync(autohandHome);
26+
writeFileSync(entryPath, `
27+
import { getProviderModelOptions } from ${JSON.stringify(catalogModulePath)};
28+
29+
const fantail = getProviderModelOptions("autohandai")
30+
.find((model) => model.id === "fantail");
31+
if (fantail?.contextWindow !== 64_000 || fantail.maxTokens !== 16_000) {
32+
throw new Error("Standalone binary is missing required Fantail metadata.");
33+
}
34+
console.log("catalog-ok");
35+
`);
36+
37+
try {
38+
execFileSync("bun", [
39+
"build",
40+
entryPath,
41+
"--compile",
42+
"--outfile",
43+
binaryPath,
44+
], { cwd: ROOT, stdio: "pipe" });
45+
chmodSync(binaryPath, 0o755);
46+
47+
const output = execFileSync(binaryPath, [], {
48+
cwd: runDirectory,
49+
encoding: "utf8",
50+
env: { ...process.env, AUTOHAND_HOME: autohandHome },
51+
stdio: ["ignore", "pipe", "pipe"],
52+
});
53+
54+
expect(output).toContain("catalog-ok");
55+
} finally {
56+
rmSync(directory, { recursive: true, force: true });
57+
}
58+
}, 30_000);
59+
});

0 commit comments

Comments
 (0)