mirror of https://github.com/openclaw/openclaw.git
test: reduce docker setup e2e duplication
This commit is contained in:
parent
d9fb1e0e45
commit
94531fa237
|
|
@ -113,6 +113,26 @@ function runDockerSetup(
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function runDockerSetupWithUnsetGatewayToken(
|
||||||
|
sandbox: DockerSetupSandbox,
|
||||||
|
suffix: string,
|
||||||
|
prepare?: (configDir: string) => Promise<void>,
|
||||||
|
) {
|
||||||
|
const configDir = join(sandbox.rootDir, `config-${suffix}`);
|
||||||
|
const workspaceDir = join(sandbox.rootDir, `workspace-${suffix}`);
|
||||||
|
await mkdir(configDir, { recursive: true });
|
||||||
|
await prepare?.(configDir);
|
||||||
|
|
||||||
|
const result = runDockerSetup(sandbox, {
|
||||||
|
OPENCLAW_GATEWAY_TOKEN: undefined,
|
||||||
|
OPENCLAW_CONFIG_DIR: configDir,
|
||||||
|
OPENCLAW_WORKSPACE_DIR: workspaceDir,
|
||||||
|
});
|
||||||
|
const envFile = await readFile(join(sandbox.rootDir, ".env"), "utf8");
|
||||||
|
|
||||||
|
return { result, envFile };
|
||||||
|
}
|
||||||
|
|
||||||
async function withUnixSocket<T>(socketPath: string, run: () => Promise<T>): Promise<T> {
|
async function withUnixSocket<T>(socketPath: string, run: () => Promise<T>): Promise<T> {
|
||||||
const server = createServer();
|
const server = createServer();
|
||||||
await new Promise<void>((resolve, reject) => {
|
await new Promise<void>((resolve, reject) => {
|
||||||
|
|
@ -243,52 +263,39 @@ describe("docker-setup.sh", () => {
|
||||||
|
|
||||||
it("reuses existing config token when OPENCLAW_GATEWAY_TOKEN is unset", async () => {
|
it("reuses existing config token when OPENCLAW_GATEWAY_TOKEN is unset", async () => {
|
||||||
const activeSandbox = requireSandbox(sandbox);
|
const activeSandbox = requireSandbox(sandbox);
|
||||||
const configDir = join(activeSandbox.rootDir, "config-token-reuse");
|
const { result, envFile } = await runDockerSetupWithUnsetGatewayToken(
|
||||||
const workspaceDir = join(activeSandbox.rootDir, "workspace-token-reuse");
|
activeSandbox,
|
||||||
await mkdir(configDir, { recursive: true });
|
"token-reuse",
|
||||||
await writeFile(
|
async (configDir) => {
|
||||||
join(configDir, "openclaw.json"),
|
await writeFile(
|
||||||
JSON.stringify({ gateway: { auth: { mode: "token", token: "config-token-123" } } }),
|
join(configDir, "openclaw.json"),
|
||||||
|
JSON.stringify({ gateway: { auth: { mode: "token", token: "config-token-123" } } }),
|
||||||
|
);
|
||||||
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
const result = runDockerSetup(activeSandbox, {
|
|
||||||
OPENCLAW_GATEWAY_TOKEN: undefined,
|
|
||||||
OPENCLAW_CONFIG_DIR: configDir,
|
|
||||||
OPENCLAW_WORKSPACE_DIR: workspaceDir,
|
|
||||||
});
|
|
||||||
|
|
||||||
expect(result.status).toBe(0);
|
expect(result.status).toBe(0);
|
||||||
const envFile = await readFile(join(activeSandbox.rootDir, ".env"), "utf8");
|
|
||||||
expect(envFile).toContain("OPENCLAW_GATEWAY_TOKEN=config-token-123"); // pragma: allowlist secret
|
expect(envFile).toContain("OPENCLAW_GATEWAY_TOKEN=config-token-123"); // pragma: allowlist secret
|
||||||
});
|
});
|
||||||
|
|
||||||
it("reuses existing .env token when OPENCLAW_GATEWAY_TOKEN and config token are unset", async () => {
|
it("reuses existing .env token when OPENCLAW_GATEWAY_TOKEN and config token are unset", async () => {
|
||||||
const activeSandbox = requireSandbox(sandbox);
|
const activeSandbox = requireSandbox(sandbox);
|
||||||
const configDir = join(activeSandbox.rootDir, "config-dotenv-token-reuse");
|
|
||||||
const workspaceDir = join(activeSandbox.rootDir, "workspace-dotenv-token-reuse");
|
|
||||||
await mkdir(configDir, { recursive: true });
|
|
||||||
await writeFile(
|
await writeFile(
|
||||||
join(activeSandbox.rootDir, ".env"),
|
join(activeSandbox.rootDir, ".env"),
|
||||||
"OPENCLAW_GATEWAY_TOKEN=dotenv-token-123\nOPENCLAW_GATEWAY_PORT=18789\n", // pragma: allowlist secret
|
"OPENCLAW_GATEWAY_TOKEN=dotenv-token-123\nOPENCLAW_GATEWAY_PORT=18789\n", // pragma: allowlist secret
|
||||||
);
|
);
|
||||||
|
const { result, envFile } = await runDockerSetupWithUnsetGatewayToken(
|
||||||
const result = runDockerSetup(activeSandbox, {
|
activeSandbox,
|
||||||
OPENCLAW_GATEWAY_TOKEN: undefined,
|
"dotenv-token-reuse",
|
||||||
OPENCLAW_CONFIG_DIR: configDir,
|
);
|
||||||
OPENCLAW_WORKSPACE_DIR: workspaceDir,
|
|
||||||
});
|
|
||||||
|
|
||||||
expect(result.status).toBe(0);
|
expect(result.status).toBe(0);
|
||||||
const envFile = await readFile(join(activeSandbox.rootDir, ".env"), "utf8");
|
|
||||||
expect(envFile).toContain("OPENCLAW_GATEWAY_TOKEN=dotenv-token-123"); // pragma: allowlist secret
|
expect(envFile).toContain("OPENCLAW_GATEWAY_TOKEN=dotenv-token-123"); // pragma: allowlist secret
|
||||||
expect(result.stderr).toBe("");
|
expect(result.stderr).toBe("");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("reuses the last non-empty .env token and strips CRLF without truncating '='", async () => {
|
it("reuses the last non-empty .env token and strips CRLF without truncating '='", async () => {
|
||||||
const activeSandbox = requireSandbox(sandbox);
|
const activeSandbox = requireSandbox(sandbox);
|
||||||
const configDir = join(activeSandbox.rootDir, "config-dotenv-last-wins");
|
|
||||||
const workspaceDir = join(activeSandbox.rootDir, "workspace-dotenv-last-wins");
|
|
||||||
await mkdir(configDir, { recursive: true });
|
|
||||||
await writeFile(
|
await writeFile(
|
||||||
join(activeSandbox.rootDir, ".env"),
|
join(activeSandbox.rootDir, ".env"),
|
||||||
[
|
[
|
||||||
|
|
@ -297,15 +304,12 @@ describe("docker-setup.sh", () => {
|
||||||
"OPENCLAW_GATEWAY_TOKEN=last=token=value\r", // pragma: allowlist secret
|
"OPENCLAW_GATEWAY_TOKEN=last=token=value\r", // pragma: allowlist secret
|
||||||
].join("\n"),
|
].join("\n"),
|
||||||
);
|
);
|
||||||
|
const { result, envFile } = await runDockerSetupWithUnsetGatewayToken(
|
||||||
const result = runDockerSetup(activeSandbox, {
|
activeSandbox,
|
||||||
OPENCLAW_GATEWAY_TOKEN: undefined,
|
"dotenv-last-wins",
|
||||||
OPENCLAW_CONFIG_DIR: configDir,
|
);
|
||||||
OPENCLAW_WORKSPACE_DIR: workspaceDir,
|
|
||||||
});
|
|
||||||
|
|
||||||
expect(result.status).toBe(0);
|
expect(result.status).toBe(0);
|
||||||
const envFile = await readFile(join(activeSandbox.rootDir, ".env"), "utf8");
|
|
||||||
expect(envFile).toContain("OPENCLAW_GATEWAY_TOKEN=last=token=value"); // pragma: allowlist secret
|
expect(envFile).toContain("OPENCLAW_GATEWAY_TOKEN=last=token=value"); // pragma: allowlist secret
|
||||||
expect(envFile).not.toContain("OPENCLAW_GATEWAY_TOKEN=first-token");
|
expect(envFile).not.toContain("OPENCLAW_GATEWAY_TOKEN=first-token");
|
||||||
expect(envFile).not.toContain("\r");
|
expect(envFile).not.toContain("\r");
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue