fix: isolate backlog db per project
This commit is contained in:
parent
6beb6fd412
commit
95cb13c08d
2 changed files with 32 additions and 4 deletions
|
|
@ -7,9 +7,9 @@
|
|||
*/
|
||||
import { existsSync, mkdirSync, readFileSync } from "node:fs";
|
||||
import { join } from "node:path";
|
||||
import { sfRoot } from "./paths.js";
|
||||
import {
|
||||
addBacklogItem as addBacklogItemToDb,
|
||||
isDbAvailable,
|
||||
listBacklogItems,
|
||||
openDatabase,
|
||||
removeBacklogItem as removeBacklogItemFromDb,
|
||||
|
|
@ -17,14 +17,13 @@ import {
|
|||
} from "./sf-db.js";
|
||||
|
||||
function ensureBacklogDb(basePath) {
|
||||
if (isDbAvailable()) return true;
|
||||
const sfDir = join(basePath, ".sf");
|
||||
const sfDir = sfRoot(basePath);
|
||||
mkdirSync(sfDir, { recursive: true });
|
||||
return openDatabase(join(sfDir, "sf.db"));
|
||||
}
|
||||
|
||||
function legacyBacklogPath(basePath) {
|
||||
return join(basePath, ".sf", "WORK-QUEUE.md");
|
||||
return join(sfRoot(basePath), "WORK-QUEUE.md");
|
||||
}
|
||||
|
||||
function parseLegacyBacklog(basePath) {
|
||||
|
|
|
|||
|
|
@ -85,3 +85,32 @@ test("backlog_list_when_legacy_work_queue_exists_imports_once_to_db", async () =
|
|||
assert.equal(items[0].source, "legacy-work-queue");
|
||||
assert.match(messages.at(-1).message, /999\.7/);
|
||||
});
|
||||
|
||||
test("backlog_add_when_switching_projects_uses_current_project_db", async () => {
|
||||
const first = makeProject();
|
||||
const second = makeProject();
|
||||
mkdirSync(join(first, ".sf"), { recursive: true });
|
||||
mkdirSync(join(second, ".sf"), { recursive: true });
|
||||
const previousCwd = process.cwd();
|
||||
try {
|
||||
process.chdir(first);
|
||||
await handleBacklog("add First project item", makeCtx([]), null);
|
||||
process.chdir(second);
|
||||
await handleBacklog("add Second project item", makeCtx([]), null);
|
||||
} finally {
|
||||
process.chdir(previousCwd);
|
||||
}
|
||||
|
||||
closeDatabase();
|
||||
openDatabase(join(first, ".sf", "sf.db"));
|
||||
assert.deepEqual(
|
||||
listBacklogItems().map((item) => item.title),
|
||||
["First project item"],
|
||||
);
|
||||
closeDatabase();
|
||||
openDatabase(join(second, ".sf", "sf.db"));
|
||||
assert.deepEqual(
|
||||
listBacklogItems().map((item) => item.title),
|
||||
["Second project item"],
|
||||
);
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue