Skip to content

refactor(check): resolve update status in internal/check - #452

Merged
runkids merged 5 commits into
mainfrom
runkids/arch-444-check-resolution
Oct 6, 2026
Merged

runkids merged 5 commits into
mainfrom
runkids/arch-444-check-resolution

Conversation

@runkids

@runkids runkids commented Oct 6, 2026

Copy link
Copy Markdown
Owner

Type

  • Bug fix
  • Small improvement (docs, typo, minor refactor)
  • Feature proposal (proposals/ only — see CONTRIBUTING.md)

Linked Issue

Closes #444

What moved where

The update-status resolution (group by clone URL + branch → remote hash → all-match fast path → tree-hash slow path → per-skill status) was written out three times. It now lives once in internal/check/resolve.go.

Before After
cmd/skillshare/check.go: collectCheckItems grouping, resolveSkillStatuses, the urlInputs/urlOrder/urlHashMap plumbing in runCheck and runCheckFiltered internal/check/resolve.go
internal/server/handler_check.go: grouping loop, per-group resolution, urlBranchGroup, skillWithMetaEntry, localCheckResult internal/check/resolve.go
internal/server/handler_check_stream.go: the same loop with checked.Add(1) internal/check/resolve.go

Interface:

  • check.Plan(skills, projectRoot) *Resolution resolves skills without a remote and groups the rest by {RepoURL, Branch}.
  • (*Resolution).Remotes() / .RemoteSkills() give the counts callers need before the run (SSE start event, CLI progress total).
  • (*Resolution).Run(ctx, Options) ([]SkillResult, error) asks each remote once and returns a status per skill.
  • Options{Remote, Parallel, OnRemoteDone}: Remote is the injectable hash source (nil means GitRemote), OnRemoteDone is the progress callback.

Adapters:

  • CLI: resolveCheckSkills runs the plan with Parallel: true and feeds the progress bar.
  • SSE handler: OnRemoteDone advances the checked counter; the request context cancels the run.
  • JSON handler: no callback.
  • Both handlers share Server.planSkillCheck and dashboardSkillResults.

ParallelCheckURLs (now used only by agent checks) calls GitRemote{}.Hash instead of its own branch/HEAD switch.

Intentional behaviour changes

Statuses and payloads are unchanged; pin tests written against the old code pass on the new code. These differences remain:

  1. Order of remote groups. All three copies iterated a Go map, so group order was random per run. It is now local skills first, then remotes in first-appearance order, which is one of the orders that was already possible.
  2. CLI grouping key. The CLI used the string url + "\t" + branch; all callers now use a struct key. Only a repo_url containing a tab behaves differently, and that is not a usable git URL.
  3. CLI tree-hash fetches run inside the parallel workers. Before, the CLI probed remote hashes with 8 workers and then fetched tree hashes one remote at a time. Now a remote's tree-hash fetch runs in its worker, so up to 8 can run at once. Results are the same; timing and concurrent load differ.
  4. CLI progress timing (TTY only). The bar now advances as each remote finishes and stops after the tree-hash fetches, instead of jumping once after all probes. Off a terminal nothing is printed.

The dashboard handlers still resolve one remote at a time, on the request goroutine.

Open questions for the maintainer

Two disagreements between the CLI and the dashboard existed before this change. Both are kept as they were and are now isolated in dashboardSkillResults (internal/server/handler_check.go):

  1. stale. For a skill whose subdir was removed upstream, the CLI reports stale and the dashboard reports update_available. Should the dashboard show stale? ui/src/pages/UpdatePage.tsx currently treats any status other than update_available/error as up to date, so sending stale needs a UI change too.
  2. Fields of a skill without a remote. The CLI sends source, version and installed_at; the dashboard sends only name, status and message. Should the dashboard carry them?

Left out of scope:

  • check.URLCheckInput.Branch is no longer set by any production caller.
  • GitRemote.Hash could be a single git.GetRemoteRefHashWithAuth call (an empty branch already resolves HEAD), but that would leave git.GetRemoteHeadHashWithAuth unused, so it was not done here.
  • cmd/skillshare/update_batch.go keeps its own URL+branch grouping; it is a different flow (clone and update).

Review before opening

  • /code-review found that Run resolved every remote in a spawned goroutine even when sequential. A panic during a dashboard check would then end the server process instead of being recovered by net/http for that request. Fixed: the sequential path runs on the caller's goroutine (TestResolution_SequentialRunStaysOnTheCallersGoroutine).
  • /simplify split Run into separate sequential and parallel loops. Its other suggestions (unexporting Remote/GitRemote, merging duplicated test tables) were not applied, to keep the pin tests as written.

Checks

Run in a task-owned container from the devcontainer image, on the final commit:

  • make check — pass, exit 0 (docs-check, fmt-check, go vet, unit and integration tests; tests/integration 62.9s)
  • go test ./internal/check/... -count=1 -race — pass
  • go test ./internal/server ./cmd/skillshare -run Check -count=1 — pass

Not run: online tests (-tags online), the dashboard UI against a live server, Windows, and a real-terminal view of the CLI progress bar. Changes 3 and 4 above follow from the code and were not observed on a terminal.

Checklist

  • I've read CONTRIBUTING.md
  • Tests included and passing (make check) — for code changes
  • No unrelated changes in the diff
  • Scope is focused — one concern per PR

The CLI, GET /api/check and the check stream each carry their own copy of
the resolution sequence, and only its leaf helpers were tested. Pin what
each caller reports for every outcome, against local bare remotes, so the
copies can be merged without changing output.

Refs #444
The CLI, GET /api/check and the check stream each wrote out the same
sequence: group skills by URL and branch, ask the remote hash, skip the
tree fetch when every skill matches, otherwise compare tree hashes and
assign a status. A fix such as branch handling had to be made three
times, and the sequence could only be tested against real repositories.

internal/check now owns it as Plan and Resolution.Run, with the remote
hash source injected and a per-remote progress callback. The CLI
progress bar and the SSE counter are adapters on that callback; the JSON
handler passes none.

The callers disagreed in two places, and both behaviours are kept: the
dashboard reports a skill removed upstream as update_available where the
CLI says stale, and gives no source or version for a skill without a
remote. The server adapter narrows the result accordingly.

Refs #444
Resolution.Run started a goroutine for every remote, even without
Parallel. The dashboard handlers run sequentially and rely on net/http
recovering a panic, which it only does on the request's goroutine, so a
panic while resolving a remote would have ended the server process
instead of failing one request, as it did before the resolution moved
into internal/check.

The sequential and the parallel path are now separate loops, so the
invariant is visible instead of being spread over three Parallel checks.

Refs #444
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 6, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-06T16:22:04.429241Z 9a34f40 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@runkids runkids added the architecture Deepening opportunity: restructure modules for locality and testability label Oct 6, 2026
TestGitRemoteHash_DefaultBranchUsesAuth puts an extensionless shell
script named git first on PATH. On Windows exec.LookPath only resolves
names with a PATHEXT extension, so the script is ignored and the real
git.exe probes github.com, which answers "repository not found" for the
made-up repository. The auth env is built without any platform branch,
so the product path is unaffected; only the test double cannot work
there. Skip it for the same reason the fake-git tests in
internal/install/source_fallback_test.go already do.

Refs #444
@runkids

runkids commented Oct 6, 2026

Copy link
Copy Markdown
Owner Author

windows-test failed in run 37494655607 on one test added by this PR, TestGitRemoteHash_DefaultBranchUsesAuth:

resolve_test.go:298: Hash without branch failed: repository 'https://github.com/org/private-skills.git/' not found

Cause (test, not product). The test puts an extensionless #!/bin/sh script named git first on PATH. On Windows exec.LookPath only resolves names with a PATHEXT extension, so the script is ignored and the real git.exe runs ls-remote against github.com. The message above is GitHub's answer for the made-up repository, not the fake's Authentication failed. GitRemote.Hash → git.GetRemoteHeadHashWithAuth → install.AuthEnvForURL has no platform branch, so auth injection itself is the same on Windows.

Fix (9cc4996). Skip the test on Windows with the same stated reason as the existing fake-git tests in internal/install/source_fallback_test.go. The assertion is unchanged on Linux and macOS.

make check passes in the devcontainer image.

@runkids
runkids merged commit e5a1781 into main Oct 6, 2026
8 checks passed
@runkids
runkids deleted the runkids/arch-444-check-resolution branch October 6, 2026 17:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

architecture Deepening opportunity: restructure modules for locality and testability

Projects

None yet

Development

Successfully merging this pull request may close these issues.

check: update-status resolution is duplicated across the CLI and two dashboard handlers

1 participant