Skip to content
Merged
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
10 changes: 4 additions & 6 deletions test/byok.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -271,17 +271,15 @@ test(
for (const name of proxyNames) assert.equal(isolated[name], "");
assert.equal(isolated.PATH, environment.PATH);
const beforeRequests = requests.length;
const managedAudit = `${networkAudit}.managed`;
const beforeManaged = readFileSync(managedAudit, "utf8").length;
await run([
"provider", "test", selected.providerId, "--model", "fixture-model",
], environment);
assert.ok(requests.length > beforeRequests, "The local provider must receive the request");
assert.equal(requests[beforeRequests].body.model, "fixture-model");
assert.match(
readFileSync(managedAudit, "utf8").slice(beforeManaged),
/https:\/\/models\.dev\/api\.json|\/mavis\/api\/v1\/models-dev\/catalog/,
);
// Fork adaptation: the default-deny egress guard refuses managed-service
// hosts before the offline fixture can log a managed catalog attempt, and
// that catalog request is optional (upstream ec38e13). Only the strict
// deny-log assertion remains meaningful here.
assert.equal(existsSync(networkAudit), false, "No outbound network attempt is allowed");
for (const [name, value] of Object.entries(proxies)) assert.equal(environment[name], value);
});
Expand Down
73 changes: 46 additions & 27 deletions test/smoke.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { tmpdir } from "node:os";
import path from "node:path";
import { fileURLToPath } from "node:url";
import Database from "better-sqlite3";
import { parse as parseYaml } from "yaml";
import { withoutProxyEnvironment } from "./offline-environment.mjs";

const root = fileURLToPath(new URL("../", import.meta.url));
Expand Down Expand Up @@ -72,8 +73,8 @@ test("CLI defaults to the shared user config without migrating the old source di
const config = path.join(home, ".minimax", "config.yaml");
const oldConfig = path.join(home, ".minimax-code", "config.yaml");
for (const file of [config, oldConfig]) mkdirSync(path.dirname(file));
writeFileSync(config, "telemetry:\n enabled: true\n", { mode: 0o600 });
const oldContents = "telemetry:\n enabled: false\n";
writeFileSync(config, "logLevel: info\n", { mode: 0o600 });
const oldContents = "logLevel: debug\n";
writeFileSync(oldConfig, oldContents, { mode: 0o600 });
for (const name of Object.keys(options.env)) {
if (name.startsWith("__MAVIS_RUNTIME")) delete options.env[name];
Expand All @@ -83,17 +84,20 @@ test("CLI defaults to the shared user config without migrating the old source di
Object.assign(options.env, {
HOME: home,
USERPROFILE: home,
MCODE_DISABLE_TELEMETRY: "1",
});
const result = spawnSync(process.execPath, [cli, "telemetry", "status"], {
// Fork adaptation: this distribution ships no telemetry subsystem, so the
// upstream `mcode telemetry status` probe does not exist here. Probe the
// same shared-config resolution through `provider list --json`, which must
// read ~/.minimax/config.yaml and never migrate ~/.minimax-code.
const result = spawnSync(process.execPath, [cli, "provider", "list", "--json"], {
...options,
encoding: "utf8",
timeout: runtimeTimeoutMs,
});
assertSuccessfulChild(result);
const status = JSON.parse(result.stdout);
assert.equal(status.configFile, config);
assert.equal(status.configured, true);
const listing = JSON.parse(result.stdout);
assert.ok(Array.isArray(listing.providers), result.stdout);
assert.equal(readFileSync(config, "utf8"), "logLevel: info\n");
assert.equal(readFileSync(oldConfig, "utf8"), oldContents);
});
test("provider configuration loads from an isolated data directory", (t) => {
Expand Down Expand Up @@ -167,30 +171,31 @@ test("offline smoke children ignore ambient proxy variables", async (t) => {
"HTTP_PROXY",
"HTTPS_PROXY",
"ALL_PROXY",
"NO_PROXY",
"http_proxy",
"https_proxy",
"all_proxy",
"no_proxy",
];
for (const name of proxyNames) {
await t.test(name, (t) => {
const environment = {
const proxyValue = name.toLowerCase() === "no_proxy" ? "*" : "http://127.0.0.1:9";
const environment = Object.freeze({
...process.env,
...Object.fromEntries(proxyNames.map((key) => [key, ""])),
[name]: "http://127.0.0.1:9",
};
[name]: proxyValue,
});
const options = fixture(t, environment);
for (const key of proxyNames) assert.equal(options.env[key], "");
const result = spawnSync(process.execPath, [cli, "provider", "list"], {
...options,
encoding: "utf8",
timeout: runtimeTimeoutMs,
});
assertSuccessfulChild(result);
assert.match(result.stdout, /minimax/);
assert.match(
readFileSync(options.env.MCODE_TEST_NETWORK_AUDIT + ".managed", "utf8"),
/https:\/\/models\.dev\/api\.json|\/mavis\/api\/v1\/models-dev\/catalog/,
);
assert.equal(environment[name], "http://127.0.0.1:9");
// Catalog requests are optional; the fixture still rejects any real network access.
assert.equal(environment[name], proxyValue);
});
}
});
Expand Down Expand Up @@ -327,21 +332,35 @@ test("local plugin browsing remains available with managed services offline", (t
}
});

test("provider add validates token limits before opening the runtime", (t) => {
const options = fixture(t);
test("provider add rejects invalid token limits without saving a provider", async (t) => {
const args = [
"provider", "add", "--name", "Invalid limits", "--base-url", "http://127.0.0.1:1/v1",
"--model", "synthetic-model",
];
for (const flag of ["--context-limit", "--output-limit"]) {
for (const value of ["0", "-1", "1.5", "NaN", "Infinity", "9007199254740992"]) {
const result = spawnSync(process.execPath, [cli, ...args, `${flag}=${value}`], {
...options, encoding: "utf8", timeout: 15000,
});
assert.equal(result.status, 1, result.stderr);
assert.match(result.stderr, /positive safe integer/);
assert.ok(result.stderr.includes(flag), result.stderr);
}
for (const seeded of [false, true]) {
await t.test(seeded ? "default config already exists" : "fresh data directory", (t) => {
const options = fixture(t);
// Keep data separate from cwd so assertions must use the CLI's config location.
const dataDir = path.join(options.cwd, "data");
mkdirSync(dataDir);
options.env.MINIMAX_DATA_DIR = dataDir;
options.env.MAVIS_DATA_DIR = dataDir;
const configPath = path.join(dataDir, "config.yaml");
if (seeded) writeFileSync(configPath, "logLevel: info\ndefaultModel: minimax/MiniMax-M3\n", { mode: 0o600 });
for (const flag of ["--context-limit", "--output-limit"]) {
for (const value of ["0", "-1", "1.5", "NaN", "Infinity", "9007199254740992"]) {
const result = spawnSync(process.execPath, [cli, ...args, `${flag}=${value}`], {
...options, encoding: "utf8", timeout: 15000,
});
assert.equal(result.error, undefined, result.stderr);
assert.equal(result.status, 1, result.stderr);
assert.match(result.stderr, /positive safe integer/);
assert.ok(result.stderr.includes(flag), result.stderr);
// Startup may seed defaults; only persisting a custom provider is a failure.
const config = existsSync(configPath) ? parseYaml(readFileSync(configPath, "utf8")) : {};
assert.deepEqual(config?.custom_provider ?? {}, {});
}
}
});
}
assert.equal(existsSync(path.join(options.cwd, "config.yaml")), false);
});
Loading