Files
plugins/packages/atomcode/scripts/live-smoke.mjs
T
LEOLI 8765cf8f9c atomcode 0.3.0: AtomGit CodingPlan provider plugin (LILEOO, #716)
Adds packages/atomcode (@magpie-community/opencode-atomcode-auth 0.3.0), an AtomGit CodingPlan provider: browser OAuth and AtomCode CLI sign-in (~/.atomcode/auth.toml), signed requests to AtomGit's own gateway, per-account models and quota, daily claim, a loopback-only diagnostics page, and OpenCode 1.x/2.x entries. Registry and README entries added. By LILEOO.

Reviewed at c57b099fff4689c0198c1c6414f04b27614b4092. The last blocking point (an inline TOML comment on a known line went into the uid and was written back) is fixed: values end at an unquoted #, quoted/escaped/literal strings keep their #, and a rewritten line keeps its comment.

Run on a separate test machine (Bun 1.4.2, sandbox HOME):
- PR head merged onto origin/main 24da52b8: bun scripts/check.mjs exit 0 (atomcode ok); whole-repo bun test 6103 pass, 0 fail. origin/main alone: 5942 pass, 0 fail.
- packages/atomcode at the head: bun test 161 pass; node --test test/*.test.mjs 161 pass.
- The new auth-file test against 55ff272's auth-file.mjs: red (1 fail), green at the head.
- Probe: the review's file (id = "123456" # c) parses to uid 123456 and renders back as id = "123456" # c; also #c with no space, CRLF with a tab before #, "1#2", and a literal-string id all round-trip to the same uid. At 55ff272 each gave a uid with the comment in it.

Not tried: a real AtomGit account. A [user] header with a trailing comment is refused ("no user id"), not corrupted; the CLI never writes one. First npm version needs an owner publish; until then magpie installs it from the dist branch.
2026-11-05 16:54:02 +08:00

99 lines
2.5 KiB
JavaScript

#!/usr/bin/env node
import { AtomCodePlugin } from "../index.mjs";
import {
defaultAuthFilePath,
readAuthFile,
} from "../auth-file.mjs";
import { redactText } from "../internal.mjs";
const MAX_REQUESTS = 9;
if (process.env.ATOMCODE_LIVE !== "1") {
console.error("Refusing live calls. Set ATOMCODE_LIVE=1 and run again.");
process.exit(2);
}
const realFetch = globalThis.fetch;
let requestCount = 0;
globalThis.fetch = (...args) => {
requestCount += 1;
if (requestCount > MAX_REQUESTS) {
throw new Error(`live smoke exceeded its ${MAX_REQUESTS}-request budget`);
}
return realFetch(...args);
};
const client = {
auth: {
set: async () => {},
},
app: {
log: () => {},
},
};
try {
const auth = await readAuthFile(defaultAuthFilePath());
const getAuth = async () => auth;
const plugin = await AtomCodePlugin(
{ client },
{
autoClaim: false,
autoVersion: false,
locale: "en",
},
);
const models = await plugin.provider.models({}, { auth });
const modelEntries = Object.values(models).filter(
(model) => model && typeof model === "object" && model.api?.id,
);
if (!modelEntries.length) throw new Error("live model catalog was empty");
const usage = await plugin.auth.usage(getAuth);
if (usage.signIn === "expired") throw new Error("live sign-in expired");
const { fetch: patched } = await plugin.auth.loader(getAuth);
const chatResults = [];
for (const model of modelEntries.slice(0, 3)) {
const response = await patched("https://llm-api.atomgit.com/v1/chat/completions", {
method: "POST",
headers: { "content-type": "application/json" },
body: JSON.stringify({
model: model.api.id,
stream: true,
max_tokens: 16,
messages: [{ role: "user", content: "Reply with OK." }],
}),
signal: AbortSignal.timeout(60_000),
});
if (!response.ok) throw new Error(`live chat returned HTTP ${response.status}`);
const stream = await response.text();
chatResults.push({
model: model.name,
sawUsage: /"usage"\s*:/.test(stream),
sawDone: /\[DONE\]/.test(stream),
});
}
console.log(
JSON.stringify(
{
ok: true,
requests: requestCount,
models: modelEntries.map((model) => model.name),
quotaWindows: usage.windows?.length ?? 0,
chat: chatResults,
},
null,
2,
),
);
} catch (error) {
console.error(`live smoke failed: ${redactText(error?.message ?? error)}`);
process.exitCode = 1;
} finally {
globalThis.fetch = realFetch;
}