整理远程模块
TDevOPsCICD / build-image (push) Waiting to run

This commit is contained in:
cheney
2026-06-16 16:40:34 +08:00
parent b46cddc7cf
commit e05ce19eac
14 changed files with 1154 additions and 365 deletions
BIN
View File
Binary file not shown.
+13
View File
@@ -0,0 +1,13 @@
require("../src/init")
const Remote = require("../src/remote")
async function main(){
const remote = new Remote();
await remote.init()
console.log(await remote.check())
}
main()
+100
View File
@@ -0,0 +1,100 @@
import { afterEach, beforeEach, describe, expect, test } from "bun:test";
import fs from "fs";
import os from "os";
import path from "path";
require("../src/init")
async function createRemote() {
const Remote = require("../src/remote")
const remote = new Remote();
await remote.init()
return remote
}
let tempDir;
let localStore;
beforeEach(() => {
tempDir = fs.mkdtempSync(path.resolve(os.tmpdir(), "kit-remote-test"));
localStore = $sConfig.getLocalStorePath();
});
afterEach(() => {
fs.rmSync(tempDir, { recursive: true, force: true });
});
describe("remote module public API", () => {
test("exposes documented public methods", async() => {
const remote = await createRemote();
expect(typeof remote.check).toBe("function");
expect(typeof remote.publish).toBe("function");
expect(typeof remote.install).toBe("function");
expect(typeof remote.list).toBe("function");
expect(typeof remote.use).toBe("function");
expect(typeof remote.rollback).toBe("function");
expect(typeof remote.remove).toBe("function");
});
test("check validates an available webdav client", async () => {
const remote = await createRemote();
expect(await remote.check()).toBe(true);
});
test("publish stores metadata and version artifacts in webdav layout", async () => {
const remote = await createRemote();
const projectDir = writeFixtureProject(tempDir, "1.0.0", "hello v1");
await remote.publish(projectDir);
const metadata = JSON.parse(await remote.client.getFileContents("/myapp/metadata.json", { format: "text" }));
const version = JSON.parse(await remote.client.getFileContents("/myapp/1.0.0/version.json", { format: "text" }));
const artifact = await remote.client.getFileContents("/myapp/1.0.0/any/any/myapp.txt", { format: "text" });
expect(metadata.project_id).toBe("myapp");
expect(metadata.latest_version).toBe("1.0.0");
expect(metadata.versions).toContain("1.0.0");
expect(version.artifacts[0].path).toBe("any/any/myapp.txt");
expect(artifact).toBe("hello v1");
});
test("install downloads latest matching artifact and records local state", async () => {
const remote = await createRemote();
const projectDir = writeFixtureProject(tempDir, "1.0.0", "hello v1");
await remote.publish(projectDir);
const installed = await remote.install("myapp");
const moduleRoot = path.resolve(localStore, "modules", "myapp");
const installJson = JSON.parse(fs.readFileSync(path.resolve(moduleRoot, ".meta", "install.json"), "utf-8"));
const installedFile = fs.readFileSync(path.resolve(moduleRoot, "versions", "1.0.0", "any", "any", "myapp.txt"), "utf-8");
expect(installed).toBe("1.0.0");
expect(installedFile).toBe("hello v1");
expect(installJson.current_version).toBe("1.0.0");
expect(installJson.installed_versions).toContain("1.0.0");
expect(fs.existsSync(path.resolve(moduleRoot, "current"))).toBe(true);
});
test("list use rollback and remove manage installed versions", async () => {
const remote = await createRemote();
await remote.publish(writeFixtureProject(tempDir, "1.0.0", "hello v1"));
await remote.install("myapp");
await remote.publish(writeFixtureProject(tempDir, "2.0.0", "hello v2"));
await remote.install("myapp");
expect(await remote.list("myapp")).toEqual(["1.0.0", "2.0.0"]);
await remote.rollback("myapp");
let installJson = JSON.parse(fs.readFileSync(path.resolve(localStore, "modules", "myapp", ".meta", "install.json"), "utf-8"));
expect(installJson.current_version).toBe("1.0.0");
await remote.use("myapp@2.0.0");
installJson = JSON.parse(fs.readFileSync(path.resolve(localStore, "modules", "myapp", ".meta", "install.json"), "utf-8"));
expect(installJson.current_version).toBe("2.0.0");
await remote.remove("myapp@1.0.0");
installJson = JSON.parse(fs.readFileSync(path.resolve(localStore, "modules", "myapp", ".meta", "install.json"), "utf-8"));
expect(installJson.installed_versions).toEqual(["2.0.0"]);
expect(fs.existsSync(path.resolve(localStore, "modules", "myapp", "versions", "1.0.0"))).toBe(false);
});
});
+7 -4
View File
@@ -105,10 +105,10 @@ async function main(){
// }
// );
const client = webdav.createClient(
"http://baishe.fullstack.club:5244/dav",
"http://openlist.honor3.com/dav",
{
username: "kit",
password: "kitkit"
username: "sunyard",
password: "sunyard"
}
);
@@ -136,9 +136,12 @@ async function main(){
// console.log("end")
await wUpload( client, "D:\\fullstack\\TDevOps\\Readme.md", "/test/case1/data/20250313111818/Readme.md2" )
// await wUpload( client, "D:\\fullstack\\TDevOps\\Readme.md", "/test/case1/data/20250313111818/Readme.md2" )
// await wUpload( client, "../dist/windows/kit.exe", "/modules/kit/0.1.20240227094429/Windows/X86_64/kit.exe" )
console.log("over")
}
//kit3 config remoteAuth sunyard:sunyard
//kit3 config remoteServer http://openlist.honor3.com/dav
main()