Release 2.0.0 — explicit monorepo_url, drop first-target-host inference

Breaking change. The monorepo's gitea host was previously inferred from the
first target's subrepo_url, silently coupling the two and breaking on any
multi-host setup (monorepo on host A, target on host B). v2.0.0 replaces the
inference with a required josh.monorepo_url field that mirrors subrepo_url —
same parsing, same SSH/HTTPS auth options, same shape.

- schema_version: 2 is now required; v1 configs are rejected with a clear migration error
- josh.monorepo_url is required; josh.monorepo_auth is optional (default https)
- mono_auth_url() in lib/auth.sh mirrors subrepo_auth_url()
- MONOREPO_API derives from monorepo_url's host instead of .[0].gitea_host;
  env-var override preserved as escape hatch
- initial_import() and force-push call mono_auth_url() instead of building URLs inline
- ADR-012 documents the rationale; CHANGELOG includes migration snippet

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-29 06:31:21 +03:00
parent 5e9b134168
commit b28662d3b4
16 changed files with 377 additions and 31 deletions

View File

@@ -37,3 +37,39 @@ setup() {
url=$(subrepo_auth_url)
[ "$url" = "git@gitea.test.local:ext/app-a.git" ]
}
@test "mono_auth_url returns bare URL for SSH" {
export MONOREPO_AUTH="ssh"
export MONOREPO_URL="git@code.example.io:org/monorepo.git"
local url
url=$(mono_auth_url)
[ "$url" = "git@code.example.io:org/monorepo.git" ]
}
@test "mono_auth_url injects credentials for HTTPS git@-form monorepo_url" {
export MONOREPO_AUTH="https"
export MONOREPO_URL="git@code.example.io:org/monorepo.git"
local url
url=$(mono_auth_url)
[ "$url" = "https://sync-bot:test-token-123@code.example.io/org/monorepo.git" ]
}
@test "mono_auth_url injects credentials for HTTPS https-form monorepo_url" {
export MONOREPO_AUTH="https"
export MONOREPO_URL="https://code.example.io/org/monorepo.git"
local url
url=$(mono_auth_url)
[ "$url" = "https://sync-bot:test-token-123@code.example.io/org/monorepo.git" ]
}
@test "mono_auth_url defaults to HTTPS when MONOREPO_AUTH unset" {
unset MONOREPO_AUTH
export MONOREPO_URL="https://code.example.io/org/monorepo.git"
local url
url=$(mono_auth_url)
[ "$url" = "https://sync-bot:test-token-123@code.example.io/org/monorepo.git" ]
}

View File

@@ -104,3 +104,151 @@ setup() {
run bash -c 'source "$JOSH_SYNC_ROOT/lib/core.sh"; source "$JOSH_SYNC_ROOT/lib/config.sh"; parse_config "nonexistent.yml"'
[ "$status" -ne 0 ]
}
@test "parse_config fails when schema_version is missing (no v1 fallback)" {
cd "$(mktemp -d)"
cat > .josh-sync.yml <<'YAML'
josh:
proxy_url: "https://josh.test.local"
monorepo_path: "org/repo"
monorepo_url: "git@gitea.test.local:org/repo.git"
targets:
- name: "x"
subfolder: "x"
subrepo_url: "git@gitea.test.local:ext/x.git"
branches: { main: main }
bot:
name: "b"
email: "b@b"
trailer: "T"
YAML
run bash -c 'source "$JOSH_SYNC_ROOT/lib/core.sh"; source "$JOSH_SYNC_ROOT/lib/config.sh"; parse_config ".josh-sync.yml"'
[ "$status" -ne 0 ]
[[ "$output" == *"schema_version missing"* ]]
}
@test "parse_config rejects schema_version: 1" {
cd "$(mktemp -d)"
cat > .josh-sync.yml <<'YAML'
schema_version: 1
josh:
proxy_url: "https://josh.test.local"
monorepo_path: "org/repo"
monorepo_url: "git@gitea.test.local:org/repo.git"
targets:
- name: "x"
subfolder: "x"
subrepo_url: "git@gitea.test.local:ext/x.git"
branches: { main: main }
bot:
name: "b"
email: "b@b"
trailer: "T"
YAML
run bash -c 'source "$JOSH_SYNC_ROOT/lib/core.sh"; source "$JOSH_SYNC_ROOT/lib/config.sh"; parse_config ".josh-sync.yml"'
[ "$status" -ne 0 ]
[[ "$output" == *"Unsupported schema_version"* ]] || [[ "$output" == *"requires schema_version 2"* ]]
}
@test "parse_config fails when josh.monorepo_url is missing" {
cd "$(mktemp -d)"
cat > .josh-sync.yml <<'YAML'
schema_version: 2
josh:
proxy_url: "https://josh.test.local"
monorepo_path: "org/repo"
targets:
- name: "x"
subfolder: "x"
subrepo_url: "git@gitea.test.local:ext/x.git"
branches: { main: main }
bot:
name: "b"
email: "b@b"
trailer: "T"
YAML
run bash -c 'source "$JOSH_SYNC_ROOT/lib/core.sh"; source "$JOSH_SYNC_ROOT/lib/config.sh"; parse_config ".josh-sync.yml"'
[ "$status" -ne 0 ]
[[ "$output" == *"monorepo_url"* ]]
}
@test "parse_config exports MONOREPO_URL, MONOREPO_AUTH, MONOREPO_GITEA_HOST, MONOREPO_REPO_PATH from SSH form" {
cd "$(mktemp -d)"
cp "$FIXTURES/minimal.yml" .josh-sync.yml
parse_config ".josh-sync.yml"
[ "$MONOREPO_URL" = "git@gitea.test.local:org/repo.git" ]
[ "$MONOREPO_AUTH" = "https" ]
[ "$MONOREPO_GITEA_HOST" = "gitea.test.local" ]
[ "$MONOREPO_REPO_PATH" = "org/repo" ]
}
@test "parse_config derives MONOREPO_GITEA_HOST from HTTPS monorepo_url" {
cd "$(mktemp -d)"
cat > .josh-sync.yml <<'YAML'
schema_version: 2
josh:
proxy_url: "https://josh.test.local"
monorepo_path: "org/repo"
monorepo_url: "https://gitea.example.io/org/repo.git"
targets:
- name: "x"
subfolder: "x"
subrepo_url: "git@gitea.test.local:ext/x.git"
branches: { main: main }
bot:
name: "b"
email: "b@b"
trailer: "T"
YAML
parse_config ".josh-sync.yml"
[ "$MONOREPO_GITEA_HOST" = "gitea.example.io" ]
[ "$MONOREPO_REPO_PATH" = "org/repo" ]
}
@test "parse_config derives MONOREPO_API from monorepo_url's host (cross-host: monorepo and target on different hosts)" {
cd "$(mktemp -d)"
cat > .josh-sync.yml <<'YAML'
schema_version: 2
josh:
proxy_url: "https://josh.example.io"
monorepo_path: "org/repo"
monorepo_url: "git@code.example.io:org/repo.git"
targets:
- name: "x"
subfolder: "x"
subrepo_url: "git@other-host.io:ext/x.git"
branches: { main: main }
bot:
name: "b"
email: "b@b"
trailer: "T"
YAML
parse_config ".josh-sync.yml"
[ "$MONOREPO_API" = "https://code.example.io/api/v1/repos/org/repo" ]
}
@test "parse_config rejects invalid monorepo_auth value" {
cd "$(mktemp -d)"
cat > .josh-sync.yml <<'YAML'
schema_version: 2
josh:
proxy_url: "https://josh.test.local"
monorepo_path: "org/repo"
monorepo_url: "git@gitea.test.local:org/repo.git"
monorepo_auth: "weird"
targets:
- name: "x"
subfolder: "x"
subrepo_url: "git@gitea.test.local:ext/x.git"
branches: { main: main }
bot:
name: "b"
email: "b@b"
trailer: "T"
YAML
run bash -c 'source "$JOSH_SYNC_ROOT/lib/core.sh"; source "$JOSH_SYNC_ROOT/lib/config.sh"; parse_config ".josh-sync.yml"'
[ "$status" -ne 0 ]
[[ "$output" == *"monorepo_auth"* ]]
}