Ark tells a Coding Plan's or Agent Plan's 5-hour, weekly and monthly
windows only to the account's control plane (GetCodingPlanUsage,
GetAFPUsage on open.volcengineapi.com), signed with the account's
AccessKey ID and Secret, never to the plan's inference key. An Ark
provider's editor now takes that access key, and the Usage page shows the
plan's windows as a card.
From yayoinoyume's feat/volcengine-usage, reviewed and reworked:
- Signing is volc-sdk-golang's (base/sign.go GetSignRequest, 06f9ef66):
signed headers sorted (content-type;host;x-content-sha256;x-date), only
Action and Version in the query. The branch signed them unsorted and put
Region in the query. TestVolcSignMatchesSDK pins two signatures the SDK
made.
- The card is in PlanQuotas beside the Step Plan's (its cache, last
reading, refresh and `magpie quota wait`), not in the subscription
cards. One per access key and plan.
- The plan is the endpoint's: /api/coding asks GetCodingPlanUsage,
/api/plan GetAFPUsage, pay-as-you-go none, in the host's region. The
branch asked both and showed whichever answered.
- Dropped guessed reply fields; the Coding Plan reply is the one
pi-ark-usage, dsh-ark-quota and ArkCodingPlanUsage read. AFP buckets are
read in the forms dsh-ark-quota and arkcli read (Used of Quota or Total,
or Percent), plus Tier; none was seen from a real account.
- An Ark provider is known by its host, not the preset id, so a copy or a
custom provider takes the key too.
- The Secret is never sent to the page (accessKey {id, secretSet}); a
blank Secret keeps it, a save without the ID keeps both, Remove
(clearAccessKey) drops both, an ID with no Secret is refused.
- The pair goes where keys go: AddCopy, Restore, Mirror, backups and
davsync carry it only with keys (withoutKeys), and a keyless restore or
sync keeps this machine's. CLI: access.key, access.secret.
- A changed access key drops the cached cards (ForgetPlanQuotas).
- UI strings in zh, zh-TW, ja and de.
Nothing was tried against the real Volcengine API: there was no access
key. A local fake checked the real request PlanQuotas makes against
volc-sdk-golang's own GetSignRequest (both actions, two regions); it
lives outside the repo, so go.mod is unchanged.
Run: gofmt -l; go vet (darwin), GOOS=linux and GOOS=windows go vet
-tags nogui on provider, gui, backup, davsync and the root; go test
-tags nogui ./internal/provider ./internal/gui ./internal/backup
./internal/davsync . under a temp HOME; node --test
volc-access-key, zhipu-team, gui-ja, gui-de, i18n-keys in Chromium and
WebKit. Fail without the change: TestVolcSignMatchesSDK (unsorted
headers), TestAddCopy, TestBackupBalanceToken, TestNoKeys,
TestTakeBalanceToken, TestSyncBalanceToken (pair not carried),
TestProviderSaveKeepsVolcengineSecret (blank Secret dropped),
volc-access-key (Remove not posted).
Co-authored-by: YAYOI27 <111715843+yayoinoyume@users.noreply.github.com>
Co-authored-by: Claude <noreply@anthropic.com>
183 lines
11 KiB
JavaScript
183 lines
11 KiB
JavaScript
// Run with Node's test runner and Playwright on the module path; see README.md.
|
|
// A Volcengine Ark plan's windows are told only to the account's access key
|
|
// (#1427): the editor of an Ark provider, saved or being added, has
|
|
// AccessKey ID and Secret Access Key. The saved Secret is never shown, only
|
|
// that one is saved; Save posts the ID as typed and a Secret only when a new
|
|
// one was typed, Remove posts clearAccessKey, and an ID with no Secret is
|
|
// refused before anything is posted. Other providers have neither and post
|
|
// none. In English and Chinese, and every string in every language.
|
|
const assert = require("node:assert/strict");
|
|
const fs = require("node:fs/promises");
|
|
const path = require("node:path");
|
|
const { test } = require("node:test");
|
|
const { chromium, webkit } = require("playwright");
|
|
|
|
const assets = path.resolve(__dirname, "../assets");
|
|
const ark = {
|
|
id: "volcengine", name: "Volcengine Ark", icon: "volcengine-color", preset: "volcengine", chat: "https://ark.cn-beijing.volces.com/api/coding/v3", responses: "https://ark.cn-beijing.volces.com/api/coding/v3", anthropic: "https://ark.cn-beijing.volces.com/api/coding", catalog: "",
|
|
models: [{ id: "ark-code-latest", name: "ark-code-latest", on: true }], agents: [], fallback: [], headers: {},
|
|
key: { set: true, masked: "…ab12" }, keyList: [], balanceToken: { takes: false, set: false }, proxy: "",
|
|
accessKey: { id: "AKLTsaved", secretSet: true },
|
|
};
|
|
const relay = {
|
|
id: "relay", name: "Relay", icon: "generic", chat: "https://relay.example.com/v1", responses: "", anthropic: "", catalog: "",
|
|
models: [{ id: "model-a", name: "Model A", on: true }], agents: [], fallback: [], headers: {},
|
|
key: { set: true, masked: "sk-…one" }, keyList: [], balanceToken: { takes: false, set: false }, proxy: "",
|
|
};
|
|
const presets = [
|
|
{ id: "volcengine", name: "Volcengine Ark", icon: "volcengine-color", kind: "vendor", chat: "https://ark.cn-beijing.volces.com/api/coding/v3", added: true, accessKey: true,
|
|
regionLabel: "Plan", regions: [{ id: "coding", name: "Coding Plan", chat: "https://ark.cn-beijing.volces.com/api/coding/v3" }, { id: "agent", name: "Agent Plan", chat: "https://ark.cn-beijing.volces.com/api/plan/v3" }] },
|
|
{ id: "deepseek", name: "DeepSeek", icon: "deepseek", kind: "vendor", chat: "https://api.deepseek.com/v1", added: false },
|
|
];
|
|
|
|
function serve(lang, posts, fresh) {
|
|
// fresh: Ark not added yet, so its tile adds a new one
|
|
const providers = fresh
|
|
? { providers: [relay], presets: presets.map((x) => ({ ...x, added: false })), excluded: [], gateway: { running: true, window: true } }
|
|
: { providers: [ark, relay], presets, excluded: [], gateway: { running: true, window: true } };
|
|
const state = { agents: [], profiles: [], settings: { lang, theme: "light" } };
|
|
return async (route) => {
|
|
const url = new URL(route.request().url());
|
|
const json = (data) => route.fulfill({ json: data });
|
|
if (url.pathname === "/boot.js") return route.fulfill({ contentType: "text/javascript", body: `window.bootPrefs = {lang:"${lang}",theme:"light",web:true};` });
|
|
if (url.pathname === "/wails/runtime.js") return route.fulfill({ contentType: "text/javascript", body: "export const Window = {};" });
|
|
if (url.pathname === "/api/state") return json(state);
|
|
if (url.pathname === "/api/providers") return json(providers);
|
|
if (url.pathname === "/api/groups") return json({ groups: [] });
|
|
if (url.pathname.startsWith("/api/provider/") && route.request().method() === "POST") {
|
|
posts.push({ action: url.pathname.slice("/api/provider/".length), body: route.request().postDataJSON() });
|
|
return json(providers);
|
|
}
|
|
if (url.pathname.startsWith("/api/")) return json({});
|
|
const file = path.join(assets, url.pathname === "/" ? "index.html" : url.pathname);
|
|
const contentType = { ".html": "text/html", ".js": "text/javascript", ".css": "text/css", ".svg": "image/svg+xml", ".png": "image/png" }[path.extname(file)];
|
|
try { await route.fulfill({ body: await fs.readFile(file), contentType }); } catch { await route.fulfill({ status: 404, body: "" }); }
|
|
};
|
|
}
|
|
|
|
const strings = [
|
|
"AccessKey ID", "Secret Access Key", "saved · paste a new one to replace it", "Remove",
|
|
"The plan's 5-hour, weekly and monthly windows are told only to the account's access key (Volcengine console → API Access Keys), not to the plan's API key. Give it here for the Usage page to show them; it is used for nothing else.",
|
|
"Give the access key's Secret too",
|
|
];
|
|
const words = {
|
|
en: { id: "AccessKey ID", secret: "Secret Access Key", saved: "saved · paste a new one to replace it", remove: "Remove", save: "Save", add: "Add", cancel: "Cancel", one: "Give the access key's Secret too" },
|
|
zh: { id: "AccessKey ID", secret: "Secret Access Key", saved: "已保存 · 粘贴新的即可替换", remove: "移除", save: "保存", add: "添加", cancel: "取消", one: "请同时填写访问密钥的 Secret" },
|
|
};
|
|
|
|
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
|
|
for (const lang of ["en", "zh"]) {
|
|
const w = words[lang];
|
|
const start = async (t, name, fresh = false) => {
|
|
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
|
|
t.after(async () => {
|
|
if (process.env.ARTIFACT_DIR) {
|
|
await fs.mkdir(process.env.ARTIFACT_DIR, { recursive: true });
|
|
await page.screenshot({ path: path.join(process.env.ARTIFACT_DIR, `${engine}-${lang}-${name}-volc-access-key.png`) });
|
|
}
|
|
await browser.close();
|
|
});
|
|
const page = await (await browser.newContext({ viewport: { width: 900, height: 560 }, reducedMotion: "reduce" })).newPage();
|
|
page.setDefaultTimeout(5000);
|
|
const errors = [];
|
|
page.on("pageerror", (e) => errors.push(e.message));
|
|
const posts = [];
|
|
await page.route("**/*", serve(lang, posts, fresh));
|
|
await page.goto("http://magpie.test/?view=providers");
|
|
return { page, errors, posts };
|
|
};
|
|
const edit = async (page, name) => {
|
|
await page.locator(".row.provider", { hasText: name }).click();
|
|
await page.locator(".editor .proxy-mode").waitFor();
|
|
};
|
|
const ak = (page) => page.locator(".editor .volc-ak");
|
|
const sk = (page) => page.locator(".editor .volc-sk");
|
|
const press = async (page, posts, label) => {
|
|
const n = posts.length;
|
|
const b = page.locator(".editor .bar").getByRole("button", { name: label, exact: true });
|
|
await b.scrollIntoViewIfNeeded();
|
|
await b.click();
|
|
for (let i = 0; i < 50 && posts.length === n; i++) await page.waitForTimeout(50);
|
|
return posts.length > n ? posts.at(-1) : null;
|
|
};
|
|
|
|
test(`${engine} ${lang}: an Ark provider's access key is shown, kept, replaced and removed`, async (t) => {
|
|
const { page, errors, posts } = await start(t, "saved");
|
|
await edit(page, "Volcengine Ark");
|
|
const labels = await page.locator(".editor label").allTextContents();
|
|
assert(labels.includes(w.id) && labels.includes(w.secret), labels.join(" | "));
|
|
assert.equal(await ak(page).inputValue(), "AKLTsaved", "the ID is shown");
|
|
assert.equal(await sk(page).inputValue(), "", "the saved Secret is not");
|
|
assert.equal(await sk(page).getAttribute("type"), "password");
|
|
assert.equal(await sk(page).getAttribute("placeholder"), w.saved);
|
|
|
|
// left as it is: the ID posted, no Secret, nothing cleared
|
|
let saved = await press(page, posts, w.save);
|
|
assert.equal(saved.action, "save");
|
|
assert.equal(saved.body.accessKeyID, "AKLTsaved");
|
|
assert(!("secretAccessKey" in saved.body) && !("clearAccessKey" in saved.body), JSON.stringify(saved.body));
|
|
|
|
// a new Secret, trimmed
|
|
await edit(page, "Volcengine Ark");
|
|
await sk(page).fill(" new-secret ");
|
|
saved = await press(page, posts, w.save);
|
|
assert.equal(saved.body.secretAccessKey, "new-secret");
|
|
assert(!("clearAccessKey" in saved.body));
|
|
|
|
// Remove clears both
|
|
await edit(page, "Volcengine Ark");
|
|
await page.locator(".editor").getByRole("button", { name: w.remove, exact: true }).first().click();
|
|
assert.equal(await ak(page).inputValue(), "");
|
|
assert.notEqual(await sk(page).getAttribute("placeholder"), w.saved);
|
|
saved = await press(page, posts, w.save);
|
|
assert.equal(saved.body.accessKeyID, "");
|
|
assert.equal(saved.body.clearAccessKey, true);
|
|
assert(!("secretAccessKey" in saved.body));
|
|
|
|
const missing = await page.evaluate((keys) => Object.fromEntries(["zh", "zh-TW", "ja", "de"].map((l) => [l, keys.filter((k) => !I18N[l][k])])), strings);
|
|
assert.deepEqual(missing, { zh: [], "zh-TW": [], ja: [], de: [] }, "every string in every language");
|
|
const border = await page.evaluate(() => [...document.querySelectorAll(".editor, .editor *")].map((e) => getComputedStyle(e).borderLeftWidth).filter((b) => parseFloat(b) > 1));
|
|
assert.deepEqual(border, [], "no border stripes");
|
|
assert.deepEqual(errors, []);
|
|
});
|
|
|
|
test(`${engine} ${lang}: another provider has no access key fields and posts none`, async (t) => {
|
|
const { page, errors, posts } = await start(t, "relay");
|
|
await edit(page, "Relay");
|
|
assert.equal(await ak(page).count(), 0);
|
|
assert.equal(await sk(page).count(), 0);
|
|
const saved = await press(page, posts, w.save);
|
|
assert.equal(saved.body.id, "relay");
|
|
assert(!("accessKeyID" in saved.body) && !("secretAccessKey" in saved.body) && !("clearAccessKey" in saved.body));
|
|
assert.deepEqual(errors, []);
|
|
});
|
|
|
|
test(`${engine} ${lang}: Ark being added takes an access key, DeepSeek doesn't, an ID alone is refused`, async (t) => {
|
|
const { page, errors, posts } = await start(t, "add", true);
|
|
await page.locator("#addProvider").click();
|
|
const sheet = page.locator("#addSheet");
|
|
await sheet.locator('.tile[data-pick="DeepSeek"]').click();
|
|
await page.locator(".editor.new").waitFor();
|
|
assert.equal(await ak(page).count(), 0, "DeepSeek has none");
|
|
await page.locator(".editor .bar").getByRole("button", { name: w.cancel, exact: true }).click();
|
|
await page.locator(".editor").waitFor({ state: "detached" });
|
|
|
|
await sheet.locator('.tile[data-pick="Volcengine Ark"]').click();
|
|
await ak(page).waitFor();
|
|
assert.equal(await sk(page).inputValue(), "");
|
|
assert.notEqual(await sk(page).getAttribute("placeholder"), w.saved, "nothing is saved yet");
|
|
await page.locator(".editor.new input[type=password]").first().fill("ark-key");
|
|
await ak(page).fill(" AKLTnew ");
|
|
assert.equal(await press(page, posts, w.add), null, "an ID with no Secret posts nothing");
|
|
assert.equal(await page.locator(".editor .editor-error").textContent(), w.one);
|
|
await sk(page).fill("sk-new");
|
|
const saved = await press(page, posts, w.add);
|
|
assert.equal(saved.body.new, true);
|
|
assert.equal(saved.body.preset, "volcengine");
|
|
assert.equal(saved.body.accessKeyID, "AKLTnew");
|
|
assert.equal(saved.body.secretAccessKey, "sk-new");
|
|
assert.deepEqual(errors, []);
|
|
});
|
|
}
|
|
}
|