aKode fase 5: rinomina interna (crate akode-*, akode-rs/, akode-cli/, binario akode, AKODE_*, ~/.akode, snapshot)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
116
akode-rs/skills/tests/openai_docs_downloads.test.mjs
Normal file
116
akode-rs/skills/tests/openai_docs_downloads.test.mjs
Normal file
@@ -0,0 +1,116 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { execFile } from "node:child_process";
|
||||
import { createHash } from "node:crypto";
|
||||
import { mkdtemp, readFile, rm } from "node:fs/promises";
|
||||
import { createServer } from "node:http";
|
||||
import { tmpdir } from "node:os";
|
||||
import path from "node:path";
|
||||
import test from "node:test";
|
||||
import { setTimeout as delay } from "node:timers/promises";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { promisify } from "node:util";
|
||||
|
||||
import { fetchCodexManual } from "../src/assets/samples/openai-docs/scripts/fetch-codex-manual.mjs";
|
||||
|
||||
const execFileAsync = promisify(execFile);
|
||||
const scripts = new URL(
|
||||
"../src/assets/samples/openai-docs/scripts/",
|
||||
import.meta.url,
|
||||
);
|
||||
const resolverScript = fileURLToPath(
|
||||
new URL("resolve-latest-model-info.cjs", scripts),
|
||||
);
|
||||
const manual = "# Codex manual\n\n## Getting started\nUse Codex.\n";
|
||||
const hash = createHash("sha256").update(manual).digest("hex");
|
||||
const markdown =
|
||||
"latestModelInfo:\n model: test-model\n migrationGuide: /migration\n promptingGuide: /prompting\n";
|
||||
|
||||
for (const failure of ["timeout", "truncated body"]) {
|
||||
test(`manual ${failure} falls back to curl before caching`, async (t) => {
|
||||
// Top-level tests run sequentially; restore proxy settings after each case.
|
||||
for (const [key, value] of Object.entries(process.env)) {
|
||||
if (/^(https?|all)_proxy$/i.test(key)) {
|
||||
delete process.env[key];
|
||||
t.after(() => {
|
||||
process.env[key] = value;
|
||||
});
|
||||
}
|
||||
}
|
||||
const cacheDir = await mkdtemp(path.join(tmpdir(), "docs-download-test-"));
|
||||
t.after(() => rm(cacheDir, { recursive: true, force: true }));
|
||||
const requests = [];
|
||||
const server = createServer((request, response) => {
|
||||
requests.push(request.method);
|
||||
response.writeHead(200, { "x-content-sha256": hash });
|
||||
response.end(manual);
|
||||
});
|
||||
await new Promise((resolve) => server.listen(0, "127.0.0.1", resolve));
|
||||
t.after(() => new Promise((resolve) => server.close(resolve)));
|
||||
const url = `http://127.0.0.1:${server.address().port}/manual`;
|
||||
const fetchMock = t.mock.method(
|
||||
globalThis,
|
||||
"fetch",
|
||||
async (_url, { method, signal }) => ({
|
||||
ok: true,
|
||||
status: 200,
|
||||
headers: new Headers({ "x-content-sha256": hash }),
|
||||
text: async () => {
|
||||
assert.notEqual(method, "HEAD", "HEAD body must not be consumed");
|
||||
if (failure === "truncated body") throw new Error("truncated body");
|
||||
// Bounded success makes the old cleared timeout fail without hanging.
|
||||
await delay(500, null, { signal });
|
||||
return manual;
|
||||
},
|
||||
}),
|
||||
);
|
||||
const result = await fetchCodexManual({
|
||||
manualUrl: url,
|
||||
cacheDir,
|
||||
timeoutMs: 25,
|
||||
});
|
||||
assert.deepEqual(
|
||||
fetchMock.mock.calls.map((call) => call.arguments[1].method),
|
||||
["HEAD", "GET"],
|
||||
);
|
||||
assert.equal(result.status.cacheStatus, "updated");
|
||||
assert.deepEqual(requests, ["GET"]);
|
||||
assert.equal(
|
||||
await readFile(path.join(cacheDir, "codex-manual.md"), "utf8"),
|
||||
manual,
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
for (const failures of [1, 3]) {
|
||||
test(`model resolver ${failures === 1 ? "retries a failed body read" : "stops after three failed body reads"}`, async () => {
|
||||
const program = `
|
||||
let calls = 0;
|
||||
globalThis.fetch = async () => ({
|
||||
ok: true, status: 200,
|
||||
text: async () => {
|
||||
if (++calls <= ${failures}) throw new Error("truncated body");
|
||||
return ${JSON.stringify(markdown)};
|
||||
},
|
||||
});
|
||||
process.on("exit", () => console.error("CALLS=" + calls));
|
||||
process.argv = [process.execPath, ${JSON.stringify(resolverScript)}, "--source", "https://example.invalid/model"];
|
||||
require(${JSON.stringify(resolverScript)});
|
||||
`;
|
||||
const result = await execFileAsync(process.execPath, ["-e", program], {
|
||||
timeout: 5000,
|
||||
}).then(
|
||||
(result) => ({ ...result, code: 0 }),
|
||||
(error) => error,
|
||||
);
|
||||
assert.equal(result.code, failures === 1 ? 0 : 1, result.stderr);
|
||||
assert.equal(
|
||||
Number(/CALLS=(\d+)/.exec(result.stderr)?.[1]),
|
||||
failures === 1 ? 2 : 3,
|
||||
);
|
||||
if (failures === 1) {
|
||||
assert.equal(JSON.parse(result.stdout).model, "test-model");
|
||||
} else {
|
||||
assert.match(result.stderr, /truncated body/);
|
||||
}
|
||||
});
|
||||
}
|
||||
137
akode-rs/skills/tests/test_skill_installer.py
Normal file
137
akode-rs/skills/tests/test_skill_installer.py
Normal file
@@ -0,0 +1,137 @@
|
||||
"""Local-only regression tests for the bundled skill-installer script.
|
||||
|
||||
Run manually; these tests are not wired into CI:
|
||||
python3 -B -m unittest discover -s akode-rs/skills/tests -p 'test_*.py'
|
||||
"""
|
||||
|
||||
import os
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
|
||||
INSTALLER = (
|
||||
Path(__file__).resolve().parents[1]
|
||||
/ "src"
|
||||
/ "assets"
|
||||
/ "samples"
|
||||
/ "skill-installer"
|
||||
/ "scripts"
|
||||
/ "install-skill-from-github.py"
|
||||
)
|
||||
|
||||
|
||||
class SkillInstallerSymlinkTests(unittest.TestCase):
|
||||
def setUp(self) -> None:
|
||||
self.directory = tempfile.TemporaryDirectory()
|
||||
self.addCleanup(self.directory.cleanup)
|
||||
self.root = Path(self.directory.name)
|
||||
self.repository = self.root / "repository"
|
||||
self.skill = self.repository / "skill"
|
||||
self.skill.mkdir(parents=True)
|
||||
(self.skill / "SKILL.md").write_text("Synthetic test skill\n", encoding="utf-8")
|
||||
self.destination = self.root / "installed"
|
||||
|
||||
def create_symlink(self, link: Path, target: Path | str) -> None:
|
||||
try:
|
||||
link.symlink_to(target)
|
||||
except OSError as error:
|
||||
self.skipTest(f"symlinks are unavailable: {error}")
|
||||
|
||||
def run_installer(self) -> subprocess.CompletedProcess[str]:
|
||||
subprocess.run(
|
||||
["git", "init", "--initial-branch=main", str(self.repository)],
|
||||
check=True,
|
||||
capture_output=True,
|
||||
text=True,
|
||||
)
|
||||
subprocess.run(
|
||||
["git", "-C", str(self.repository), "add", "."],
|
||||
check=True,
|
||||
capture_output=True,
|
||||
text=True,
|
||||
)
|
||||
subprocess.run(
|
||||
[
|
||||
"git",
|
||||
"-C",
|
||||
str(self.repository),
|
||||
"-c",
|
||||
"user.name=Skill Installer Test",
|
||||
"-c",
|
||||
"user.email=skill-installer@example.invalid",
|
||||
"commit",
|
||||
"-m",
|
||||
"synthetic skill fixture",
|
||||
],
|
||||
check=True,
|
||||
capture_output=True,
|
||||
text=True,
|
||||
)
|
||||
|
||||
environment = os.environ.copy()
|
||||
python_path = [str(INSTALLER.parent)]
|
||||
if environment.get("PYTHONPATH"):
|
||||
python_path.append(environment["PYTHONPATH"])
|
||||
environment.update(
|
||||
{
|
||||
"GIT_CONFIG_COUNT": "2",
|
||||
"GIT_CONFIG_KEY_0": f"url.{self.repository.as_uri()}.insteadOf",
|
||||
"GIT_CONFIG_VALUE_0": "https://github.com/synthetic/fixture.git",
|
||||
"GIT_CONFIG_KEY_1": "core.symlinks",
|
||||
"GIT_CONFIG_VALUE_1": "true",
|
||||
"GIT_TERMINAL_PROMPT": "0",
|
||||
"PYTHONPATH": os.pathsep.join(python_path),
|
||||
}
|
||||
)
|
||||
return subprocess.run(
|
||||
[
|
||||
sys.executable,
|
||||
"-B",
|
||||
str(INSTALLER),
|
||||
"--repo",
|
||||
"synthetic/fixture",
|
||||
"--path",
|
||||
"skill",
|
||||
"--method",
|
||||
"git",
|
||||
"--dest",
|
||||
str(self.destination),
|
||||
],
|
||||
capture_output=True,
|
||||
text=True,
|
||||
check=False,
|
||||
env=environment,
|
||||
)
|
||||
|
||||
def test_rejects_symlink_to_file_outside_skill(self) -> None:
|
||||
outside_file = self.root / "synthetic-secret.txt"
|
||||
outside_file.write_text("synthetic secret\n", encoding="utf-8")
|
||||
self.create_symlink(self.skill / "outside.txt", outside_file)
|
||||
|
||||
result = self.run_installer()
|
||||
|
||||
self.assertNotEqual(result.returncode, 0)
|
||||
self.assertIn("Unsupported symbolic link", result.stderr)
|
||||
self.assertFalse((self.destination / "skill").exists())
|
||||
|
||||
def test_installs_symlink_to_regular_file_inside_skill(self) -> None:
|
||||
(self.skill / "actual.txt").write_text(
|
||||
"safe skill contents\n", encoding="utf-8"
|
||||
)
|
||||
self.create_symlink(self.skill / "alias.txt", "actual.txt")
|
||||
|
||||
result = self.run_installer()
|
||||
|
||||
self.assertEqual(result.returncode, 0, result.stderr)
|
||||
installed_alias = self.destination / "skill" / "alias.txt"
|
||||
self.assertFalse(installed_alias.is_symlink())
|
||||
self.assertEqual(
|
||||
installed_alias.read_text(encoding="utf-8"), "safe skill contents\n"
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user