mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 06:30:43 +00:00
perf(config): use direct writes for gateway token persistence
This commit is contained in:
@@ -7,7 +7,7 @@ const resolveNodeStartupTlsEnvironmentMock = vi.hoisted(() => vi.fn());
|
||||
const loadConfigMock = vi.hoisted(() => vi.fn());
|
||||
const readConfigFileSnapshotMock = vi.hoisted(() => vi.fn());
|
||||
const resolveGatewayPortMock = vi.hoisted(() => vi.fn(() => 18789));
|
||||
const replaceConfigFileMock = vi.hoisted(() => vi.fn());
|
||||
const writeConfigFileMock = vi.hoisted(() => vi.fn());
|
||||
const resolveIsNixModeMock = vi.hoisted(() => vi.fn(() => false));
|
||||
const resolveSecretInputRefMock = vi.hoisted(() =>
|
||||
vi.fn((): { ref: unknown } => ({ ref: undefined })),
|
||||
@@ -80,7 +80,11 @@ vi.mock("../../config/paths.js", () => ({
|
||||
|
||||
vi.mock("../../commands/gateway-install-token.persist.runtime.js", () => ({
|
||||
readConfigFileSnapshot: readConfigFileSnapshotMock,
|
||||
replaceConfigFile: replaceConfigFileMock,
|
||||
readConfigFileSnapshotForWrite: vi.fn(async () => ({
|
||||
snapshot: await readConfigFileSnapshotMock(),
|
||||
writeOptions: { expectedConfigPath: "/tmp/openclaw.json" },
|
||||
})),
|
||||
writeConfigFile: writeConfigFileMock,
|
||||
}));
|
||||
|
||||
vi.mock("../../config/types.secrets.js", () => ({
|
||||
@@ -172,7 +176,7 @@ describe("runDaemonInstall", () => {
|
||||
resolveNodeStartupTlsEnvironmentMock.mockReset();
|
||||
readConfigFileSnapshotMock.mockReset();
|
||||
resolveGatewayPortMock.mockClear();
|
||||
replaceConfigFileMock.mockReset();
|
||||
writeConfigFileMock.mockReset();
|
||||
resolveIsNixModeMock.mockReset();
|
||||
resolveSecretInputRefMock.mockReset();
|
||||
resolveGatewayAuthMock.mockReset();
|
||||
@@ -251,7 +255,7 @@ describe("runDaemonInstall", () => {
|
||||
expect(actionState.failed).toEqual([]);
|
||||
expect(buildGatewayInstallPlanMock).toHaveBeenCalledTimes(1);
|
||||
expectFirstInstallPlanCallOmitsToken();
|
||||
expect(replaceConfigFileMock).not.toHaveBeenCalled();
|
||||
expect(writeConfigFileMock).not.toHaveBeenCalled();
|
||||
expect(
|
||||
actionState.warnings.some((warning) =>
|
||||
warning.includes("gateway.auth.token is SecretRef-managed"),
|
||||
@@ -285,13 +289,11 @@ describe("runDaemonInstall", () => {
|
||||
await runDaemonInstall({ json: true });
|
||||
|
||||
expect(actionState.failed).toEqual([]);
|
||||
expect(replaceConfigFileMock).toHaveBeenCalledTimes(1);
|
||||
const writtenConfig = replaceConfigFileMock.mock.calls[0]?.[0] as {
|
||||
nextConfig?: {
|
||||
gateway?: { auth?: { token?: string } };
|
||||
};
|
||||
expect(writeConfigFileMock).toHaveBeenCalledTimes(1);
|
||||
const writtenConfig = writeConfigFileMock.mock.calls[0]?.[0] as {
|
||||
gateway?: { auth?: { token?: string } };
|
||||
};
|
||||
expect(writtenConfig.nextConfig?.gateway?.auth?.token).toBe("minted-token");
|
||||
expect(writtenConfig.gateway?.auth?.token).toBe("minted-token");
|
||||
expect(buildGatewayInstallPlanMock).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ port: 18789 }),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user