Auto-migrate legacy enterprise directory and drop legacy reads
This commit is contained in:
1 parent
08cbc541b4
commit
3d16857aeb
2 files changed
+118
-5
No files matched your search
@@ -1,5 +1,5 @@
|
||||
import { afterEach, describe, expect, test } from "bun:test";
|
||||
import { mkdtempSync, mkdirSync, rmSync, writeFileSync } from "node:fs";
|
||||
import { existsSync, mkdirSync, mkdtempSync, rmSync, utimesSync, writeFileSync } from "node:fs";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import {
|
||||
@@ -9,6 +9,7 @@ import {
|
||||
resolveEnterprisesDir,
|
||||
resolveGlobalConfigFile,
|
||||
saveGlobalConfig,
|
||||
syncLegacyEnterprisesDir,
|
||||
updateCorpConfig
|
||||
} from "./loader.js";
|
||||
|
||||
@@ -187,6 +188,39 @@ describe("loadCorpConfigs", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("syncLegacyEnterprisesDir", () => {
|
||||
test("migrates files from legacy to primary and deletes legacy when > 7 days old", () => {
|
||||
const primary = makeTempDir();
|
||||
const legacy = makeTempDir();
|
||||
|
||||
writeCorpConfig(join(legacy, "old-corp.json"), "old-corp", "Old Corp");
|
||||
|
||||
const tenDaysAgo = (Date.now() - 10 * 24 * 60 * 60 * 1000) / 1000;
|
||||
utimesSync(join(legacy, "old-corp.json"), tenDaysAgo, tenDaysAgo);
|
||||
utimesSync(legacy, tenDaysAgo, tenDaysAgo);
|
||||
|
||||
const result = syncLegacyEnterprisesDir(primary, legacy);
|
||||
expect(result.copied).toEqual(["old-corp.json"]);
|
||||
expect(result.deletedLegacyDir).toBe(true);
|
||||
|
||||
expect(existsSync(join(primary, "old-corp.json"))).toBe(true);
|
||||
expect(existsSync(legacy)).toBe(false);
|
||||
});
|
||||
|
||||
test("preserves legacy directory when modified within 7 days", () => {
|
||||
const primary = makeTempDir();
|
||||
const legacy = makeTempDir();
|
||||
|
||||
writeCorpConfig(join(legacy, "recent-corp.json"), "recent-corp", "Recent Corp");
|
||||
const result = syncLegacyEnterprisesDir(primary, legacy);
|
||||
expect(result.copied).toEqual(["recent-corp.json"]);
|
||||
expect(result.deletedLegacyDir).toBe(false);
|
||||
|
||||
expect(existsSync(join(primary, "recent-corp.json"))).toBe(true);
|
||||
expect(existsSync(legacy)).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
function makeTempDir(): string {
|
||||
const dir = mkdtempSync(join(tmpdir(), "seal-home-loader-"));
|
||||
mkdirSync(dir, { recursive: true });
|
||||
|
||||
Reference in new issue
Block a user