finalize
This commit is contained in:
@@ -14,9 +14,11 @@ import {
|
||||
pruneInstances,
|
||||
readInstances,
|
||||
readManifest,
|
||||
refreshDiscovery,
|
||||
writeInstance,
|
||||
writeManifest,
|
||||
} from "../out/agent/instances.js";
|
||||
import { endpointPath, readEndpoint } from "../out/agent/endpoint.js";
|
||||
|
||||
function instanceHome() {
|
||||
return mkdtempSync(join(tmpdir(), "ra3-instances-"));
|
||||
@@ -166,3 +168,52 @@ test("makeInstanceId is unique across rapid calls", () => {
|
||||
assert.equal(ids.size, 200);
|
||||
for (const id of ids) assert.ok(id.startsWith("1234-"), id);
|
||||
});
|
||||
|
||||
test("refreshDiscovery keeps surviving windows discoverable", async () => {
|
||||
const home = instanceHome();
|
||||
try {
|
||||
const mine = makeInstance("mine");
|
||||
const other = {
|
||||
...makeInstance("other"),
|
||||
url: "http://127.0.0.1:19999",
|
||||
token: "tok-other",
|
||||
projectDir: "D:/Mods/Beta",
|
||||
projects: ["D:/Mods/Beta"],
|
||||
};
|
||||
await writeInstance(mine, home);
|
||||
await writeInstance(other, home);
|
||||
// This window closes: only its own instance file goes away.
|
||||
await clearInstance(mine.instanceId, home);
|
||||
|
||||
const manifest = await refreshDiscovery(home);
|
||||
assert.deepEqual(manifest.projects, ["D:/Mods/Beta"]);
|
||||
assert.deepEqual(manifest.instances.map((i) => i.instanceId), ["other"]);
|
||||
|
||||
// The legacy global pointer must follow the survivor, not be deleted.
|
||||
const endpoint = await readEndpoint(home);
|
||||
assert.equal(endpoint?.url, other.url);
|
||||
assert.equal(endpoint?.token, other.token);
|
||||
assert.equal(existsSync(endpointPath(home)), true);
|
||||
|
||||
// The merged manifest on disk must agree with the returned value.
|
||||
const reread = await readManifest(home);
|
||||
assert.deepEqual(reread?.instances.map((i) => i.instanceId), ["other"]);
|
||||
} finally {
|
||||
rmSync(home, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
test("refreshDiscovery clears the global pointer when the last window closes", async () => {
|
||||
const home = instanceHome();
|
||||
try {
|
||||
await writeInstance(makeInstance("only"), home);
|
||||
await clearInstance("only", home);
|
||||
|
||||
const manifest = await refreshDiscovery(home);
|
||||
assert.deepEqual(manifest.instances, []);
|
||||
assert.deepEqual(manifest.projects, []);
|
||||
assert.equal(existsSync(endpointPath(home)), false);
|
||||
} finally {
|
||||
rmSync(home, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user