Files
skills-win/tools-sync/tests/test_sync_repos_registries.ps1
T
Myfro9andClaude Opus 5 58b90f16a6 tools-sync: 合并 gitea 自愈与 junction/ingest 两条演进线
rebase 到 origin/main 时 tools-sync 三个文件都冲突——上游(SHANGHAI-U9)加了
gitea 传输自愈与 ls-remote 同步闸门,本机加了 registry 双向 ingest/修复模型。
两者互不相干,按并集合并:

- sync_repos.ps1: 保留 -NoDoctor/-AllowDestructive 与 Test-TransportFault /
  Invoke-Doctor / ls-remote 闸门,叠加 -Registry/-MirrorRegistry/-NoIngest 与
  registry 对账。上游末尾那段 stale-junction 清理引用了已删除的 $CodexSkills,
  且已被新 registry 循环覆盖,故弃用。
- SKILL.md: 保留阶段 1.5(gitea 医生)整节,阶段 2 换成 registry 对账;
  description 与阶段 6 报告模板取两侧并集。
- test_sync_repos_registries.ps1: 阶段 1 的成功串改成上游 ls-remote 闸门的
  "verified: origin/main ="。两个测试套件均通过。

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01438Zbcx49e4o46uSA71mFF
2026-09-07 16:23:13 +08:00

71 lines
4.5 KiB
PowerShell

# Covers Phase 2 of sync_repos.ps1 -- the registry reconciliation that decides whether a
# directory found on the Codex side gets ingested, collapsed, or reported. Runs against a
# throwaway primary + registries + bare origin under TEMP; the real machine is never touched.
$ErrorActionPreference = "Stop"
$scriptUnderTest = Join-Path (Split-Path $PSScriptRoot -Parent) "scripts\sync_repos.ps1"
$root = Join-Path ([IO.Path]::GetTempPath()) ("tools-sync-repos-test-" + [guid]::NewGuid().ToString("N"))
function New-Skill([string]$Path, [string]$Body) {
New-Item -ItemType Directory -Force -Path $Path | Out-Null
Set-Content -LiteralPath (Join-Path $Path "SKILL.md") -Value $Body -Encoding utf8
}
try {
$primary = Join-Path $root "primary"
$codex = Join-Path $root "codex"
$agents = Join-Path $root "agents"
New-Item -ItemType Directory -Force -Path $primary, $codex, $agents | Out-Null
# One skill of each shape the reconciler must tell apart.
New-Skill (Join-Path $primary "shared") "shared body"
New-Skill (Join-Path $primary "forked") "primary body"
New-Skill (Join-Path $agents "shared") "shared body" # identical duplicate -> collapse
New-Skill (Join-Path $agents "forked") "registry body" # divergent -> conflict
New-Skill (Join-Path $agents "codexborn") "born on the codex side" # registry-only -> ingest
New-Item -ItemType Directory -Force -Path (Join-Path $agents "notaskill") | Out-Null # no SKILL.md
# A link into the other registry rather than the primary: the drift case.
New-Item -ItemType Junction -Path (Join-Path $codex "shared") -Target (Join-Path $agents "shared") | Out-Null
# A local bare repo stands in for origin so Phase 1 completes and Phase 2 actually runs.
$origin = Join-Path $root "origin.git"
& git init --quiet --bare $origin
& git init --quiet --initial-branch=main $primary
& git -C $primary remote add origin $origin
& git -C $primary -c user.email=t@t -c user.name=t commit --quiet --allow-empty -m init
& git -C $primary push --quiet -u origin main
# Invoked via -Command, not -File: -File stringifies every argument, so a [string[]]
# parameter silently takes only its first element and the rest slide into later positions.
$ErrorActionPreference = "Continue"
$invocation = "& '$scriptUnderTest' -RepoUrl '$origin' -ClaudeSkills '$primary' " +
"-Registry @('$codex','$agents') -MirrorRegistry '$codex'"
$output = & powershell -NoProfile -ExecutionPolicy Bypass -Command $invocation 2>&1 | Out-String
$ErrorActionPreference = "Stop"
if ($output -notmatch 'INGEST registry-only skill:\s*codexborn') { throw "codex-side skill was not ingested`n$output" }
if (-not (Test-Path (Join-Path $primary "codexborn\SKILL.md"))) { throw "ingested skill is not in the primary`n$output" }
if ((Get-Item (Join-Path $agents "codexborn")).LinkType -ne "Junction") { throw "ingested skill was not linked back`n$output" }
if ($output -notmatch 'MISDIRECTED link:\s*shared') { throw "link into another registry not detected`n$output" }
$sharedTarget = (Get-Item (Join-Path $codex "shared")).Target | Select-Object -First 1
if ($sharedTarget -ne (Join-Path $primary "shared")) { throw "misdirected link not repointed at the primary, got $sharedTarget`n$output" }
if ((Get-Item (Join-Path $agents "shared")).LinkType -ne "Junction") { throw "identical duplicate did not collapse`n$output" }
if ($output -notmatch 'CONFLICT:\s*forked') { throw "divergent duplicate not reported`n$output" }
if ((Get-Item (Join-Path $agents "forked")).LinkType -eq "Junction") { throw "divergent duplicate must be left untouched`n$output" }
if ((Get-Content -Raw (Join-Path $primary "forked\SKILL.md")) -notmatch 'primary body') { throw "primary was overwritten by a conflict`n$output" }
if ($output -notmatch 'not a skill dir') { throw "directory without SKILL.md not reported`n$output" }
# Mirror registry must expose every primary skill, including the freshly ingested one.
foreach ($name in @("shared", "forked", "codexborn")) {
if (-not (Test-Path (Join-Path $codex "$name\SKILL.md"))) { throw "mirror missing $name`n$output" }
}
# Phase 1's success line is the ls-remote gate's verdict (upstream wording).
if ($output -notmatch 'verified: origin/main =') { throw "Phase 1 did not complete`n$output" }
Write-Host "PASS: registry ingest / repair / conflict fixtures"
} finally {
Remove-Item -LiteralPath $root -Recurse -Force -ErrorAction SilentlyContinue
}