fix(workspace): harden omo migration review issues
This commit is contained in:
@@ -1,5 +1,9 @@
|
||||
import type { GitFileStat } from "./types"
|
||||
|
||||
function normalizePath(path: string): string {
|
||||
return path.replaceAll("\\", "/")
|
||||
}
|
||||
|
||||
export function formatFileChanges(stats: GitFileStat[], notepadPath?: string): string {
|
||||
if (stats.length === 0) return "[FILE CHANGES SUMMARY]\nNo file changes detected.\n"
|
||||
|
||||
@@ -34,7 +38,11 @@ export function formatFileChanges(stats: GitFileStat[], notepadPath?: string): s
|
||||
}
|
||||
|
||||
if (notepadPath) {
|
||||
const notepadStat = stats.find((s) => s.path.includes("notepad") || s.path.includes(".omo"))
|
||||
const normalizedNotepadPath = normalizePath(notepadPath)
|
||||
const notepadStat = stats.find((s) => {
|
||||
const normalizedPath = normalizePath(s.path)
|
||||
return normalizedPath === normalizedNotepadPath || normalizedPath.includes(".omo/notepads/")
|
||||
})
|
||||
if (notepadStat) {
|
||||
lines.push("[NOTEPAD UPDATED]")
|
||||
lines.push(` ${notepadStat.path} (+${notepadStat.added})`)
|
||||
|
||||
@@ -48,4 +48,21 @@ describe("git-worktree", () => {
|
||||
expect(summary).toContain("src/b.ts")
|
||||
expect(summary).toContain("src/c.ts")
|
||||
})
|
||||
|
||||
test("#given notepad path #when formatting omo plan changes #then does not report notepad updated", () => {
|
||||
const summary = formatFileChanges([
|
||||
{ path: ".omo/plans/work.md", added: 1, removed: 0, status: "modified" },
|
||||
], ".omo/notepads/work/notes.md")
|
||||
|
||||
expect(summary).not.toContain("[NOTEPAD UPDATED]")
|
||||
})
|
||||
|
||||
test("#given notepad path #when formatting omo notepad changes #then reports notepad updated", () => {
|
||||
const summary = formatFileChanges([
|
||||
{ path: ".omo/notepads/work/notes.md", added: 1, removed: 0, status: "modified" },
|
||||
], ".omo/notepads/work/notes.md")
|
||||
|
||||
expect(summary).toContain("[NOTEPAD UPDATED]")
|
||||
expect(summary).toContain(".omo/notepads/work/notes.md")
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { afterEach, beforeEach, describe, expect, test } from "bun:test"
|
||||
import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs"
|
||||
import { existsSync, mkdirSync, readFileSync, rmSync, symlinkSync, writeFileSync } from "node:fs"
|
||||
import { tmpdir } from "node:os"
|
||||
import { join } from "node:path"
|
||||
import { migrateLegacyWorkspaceDirectory } from "./legacy-workspace-migration"
|
||||
@@ -72,6 +72,23 @@ describe("migrateLegacyWorkspaceDirectory", () => {
|
||||
expect(readFileSync(targetNotepadPath, "utf-8")).toBe("existing note")
|
||||
})
|
||||
|
||||
test("#given legacy workspace contains symlinks #when migrating #then skips symlinks without copying target contents", () => {
|
||||
// given
|
||||
const externalFilePath = join(testDirectory, "external-secret.md")
|
||||
const legacyLinkPath = join(testDirectory, ".sisyphus", "plans", "linked.md")
|
||||
mkdirSync(join(testDirectory, ".sisyphus", "plans"), { recursive: true })
|
||||
writeFileSync(externalFilePath, "secret", "utf-8")
|
||||
symlinkSync(externalFilePath, legacyLinkPath)
|
||||
|
||||
// when
|
||||
const result = migrateLegacyWorkspaceDirectory(testDirectory)
|
||||
|
||||
// then
|
||||
expect(result.migrated).toBe(false)
|
||||
expect(result.skipped).toContain(join(".omo", "plans", "linked.md"))
|
||||
expect(existsSync(join(testDirectory, ".omo", "plans", "linked.md"))).toBe(false)
|
||||
})
|
||||
|
||||
test("#given no legacy workspace #when migrating #then reports no migration", () => {
|
||||
// when
|
||||
const result = migrateLegacyWorkspaceDirectory(testDirectory)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { copyFileSync, existsSync, mkdirSync, readdirSync, statSync } from "node:fs"
|
||||
import { copyFileSync, existsSync, lstatSync, mkdirSync, readdirSync } from "node:fs"
|
||||
import { dirname, join, relative } from "node:path"
|
||||
|
||||
import { log } from "./logger"
|
||||
@@ -12,10 +12,15 @@ export type LegacyWorkspaceMigrationResult = {
|
||||
}
|
||||
|
||||
function copyMissingEntries(legacyPath: string, targetPath: string, targetRoot: string, skipped: string[]): boolean {
|
||||
const legacyStat = statSync(legacyPath)
|
||||
const legacyStat = lstatSync(legacyPath)
|
||||
|
||||
if (legacyStat.isSymbolicLink()) {
|
||||
skipped.push(join(WORKSPACE_DIR, relative(targetRoot, targetPath)))
|
||||
return false
|
||||
}
|
||||
|
||||
if (existsSync(targetPath)) {
|
||||
if (legacyStat.isDirectory() && statSync(targetPath).isDirectory()) {
|
||||
if (legacyStat.isDirectory() && lstatSync(targetPath).isDirectory()) {
|
||||
let copiedChild = false
|
||||
for (const entry of readdirSync(legacyPath)) {
|
||||
copiedChild = copyMissingEntries(join(legacyPath, entry), join(targetPath, entry), targetRoot, skipped) || copiedChild
|
||||
|
||||
Reference in New Issue
Block a user