mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 21:58:26 +00:00
refactor(channels): dedupe transport and gateway test scaffolds
This commit is contained in:
@@ -125,6 +125,20 @@ function createErrnoError(code: string) {
|
||||
return err;
|
||||
}
|
||||
|
||||
function mockWorkspaceStateRead(params: { onboardingCompletedAt?: string; errorCode?: string }) {
|
||||
mocks.fsReadFile.mockImplementation(async (filePath: string | URL | number) => {
|
||||
if (String(filePath).endsWith("workspace-state.json")) {
|
||||
if (params.errorCode) {
|
||||
throw createErrnoError(params.errorCode);
|
||||
}
|
||||
return JSON.stringify({
|
||||
onboardingCompletedAt: params.onboardingCompletedAt ?? "2026-02-15T14:00:00.000Z",
|
||||
});
|
||||
}
|
||||
throw createEnoentError();
|
||||
});
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
mocks.fsReadFile.mockImplementation(async () => {
|
||||
throw createEnoentError();
|
||||
@@ -413,14 +427,7 @@ describe("agents.files.list", () => {
|
||||
});
|
||||
|
||||
it("hides BOOTSTRAP.md when workspace onboarding is complete", async () => {
|
||||
mocks.fsReadFile.mockImplementation(async (filePath: string | URL | number) => {
|
||||
if (String(filePath).endsWith("workspace-state.json")) {
|
||||
return JSON.stringify({
|
||||
onboardingCompletedAt: "2026-02-15T14:00:00.000Z",
|
||||
});
|
||||
}
|
||||
throw createEnoentError();
|
||||
});
|
||||
mockWorkspaceStateRead({ onboardingCompletedAt: "2026-02-15T14:00:00.000Z" });
|
||||
|
||||
const { respond, promise } = makeCall("agents.files.list", { agentId: "main" });
|
||||
await promise;
|
||||
@@ -431,12 +438,7 @@ describe("agents.files.list", () => {
|
||||
});
|
||||
|
||||
it("falls back to showing BOOTSTRAP.md when workspace state cannot be read", async () => {
|
||||
mocks.fsReadFile.mockImplementation(async (filePath: string | URL | number) => {
|
||||
if (String(filePath).endsWith("workspace-state.json")) {
|
||||
throw createErrnoError("EACCES");
|
||||
}
|
||||
throw createEnoentError();
|
||||
});
|
||||
mockWorkspaceStateRead({ errorCode: "EACCES" });
|
||||
|
||||
const { respond, promise } = makeCall("agents.files.list", { agentId: "main" });
|
||||
await promise;
|
||||
|
||||
Reference in New Issue
Block a user