Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion assets/skills/_shared/references/openspec.js
Original file line number Diff line number Diff line change
Expand Up @@ -581,14 +581,23 @@ async function resolveArchivedChangeLocation(projectDir, slug) {
return null
}

const matchesArchivedSlug = (entryName) => {
if (entryName === slug) {
return true
}

const datedMatch = entryName.match(/^\d{4}-\d{2}-\d{2}-(.+)$/)
return datedMatch?.[1] === slug
}

const entries = await readdir(archivedRoot, { withFileTypes: true })
for (const entry of entries) {
if (!entry.isDirectory()) {
continue
}

const dirPath = path.join(archivedRoot, entry.name)
if (entry.name === slug || entry.name.endsWith(`-${slug}`)) {
if (matchesArchivedSlug(entry.name)) {
return {
dirPath,
slug,
Expand Down
20 changes: 20 additions & 0 deletions test/reference-scripts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { promisify } from "node:util"

import { afterEach, beforeEach, describe, expect, it } from "vitest"

import { resolveChangeLocation } from "../assets/skills/_shared/references/openspec.js"

const execFileAsync = promisify(execFile)
const tempDirs: string[] = []

Expand Down Expand Up @@ -130,4 +132,22 @@ describe("reference scripts", () => {
expect(archived.specsMergedTo).toEqual(["openspec/specs/archive-change/spec.md"])
expect(await exists(path.join(projectDir, "openspec", "specs", "archive-change", "spec.md"))).toBe(true)
})

it("archived change lookup does not match suffix-only slugs", async () => {
const projectDir = await createWorkspace()
const archiveDir = path.join(projectDir, "openspec", "changes", "archive", "2026-01-01-add-user-auth")
await mkdir(archiveDir, { recursive: true })
await writeFile(
path.join(archiveDir, "proposal.md"),
'---\nslug: "add-user-auth"\ncreatedAt: "2026-01-01T00:00:00.000Z"\n---\n\n# Proposal\n',
"utf8",
)

await expect(resolveChangeLocation(projectDir, "add-user-auth")).resolves.toMatchObject({
dirPath: archiveDir,
slug: "add-user-auth",
status: "archived",
})
await expect(resolveChangeLocation(projectDir, "user-auth")).resolves.toBeNull()
})
})
Loading