Skip to content

Commit faa1040

Browse files
mevdscheeclaude
andcommitted
api: add --debug-compare for one-shot local-vs-GitHub parity checks
The `api` passthrough can now compare its locally-served answer against api.github.com synchronously and log any divergence (normalized, deduped via internal/shadow). Completes the shadow-compare surface on serve + api; the one-shot form is handy for capturing the exact queries gh/MCP emit. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent e3929e5 commit faa1040

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

api.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package main
22

33
import (
4+
"context"
45
"flag"
56
"fmt"
67
"io"
@@ -14,6 +15,7 @@ import (
1415
"github.com/mevdschee/github-export/internal/graphqlmirror"
1516
"github.com/mevdschee/github-export/internal/httpapi"
1617
"github.com/mevdschee/github-export/internal/query"
18+
"github.com/mevdschee/github-export/internal/shadow"
1719
"github.com/mevdschee/github-export/internal/store"
1820
"github.com/mevdschee/github-export/internal/sync"
1921
"github.com/mevdschee/github-export/internal/writeproxy"
@@ -29,6 +31,7 @@ func runAPI(args []string) {
2931
input := fs.String("input", "", "request body file ('-' for stdin)")
3032
proxyMode := fs.String("proxy", "on", "proxy fallback: on|off")
3133
repoPath := fs.String("repo-path", ".", "local git clone for content endpoints")
34+
debugCompare := fs.Bool("debug-compare", false, "also fetch the path from GitHub and log any divergence from the local answer")
3235
fs.Usage = func() {
3336
fmt.Fprintf(os.Stderr, "Usage: %s api [flags] <path>\n\n", os.Args[0])
3437
fmt.Fprintf(os.Stderr, "Makes a single GitHub-API request, served locally when mirrored and proxied\n")
@@ -107,7 +110,17 @@ func runAPI(args []string) {
107110
srv.Handler().ServeHTTP(rec, req)
108111

109112
res := rec.Result()
110-
io.Copy(os.Stdout, res.Body)
113+
out, _ := io.ReadAll(res.Body)
114+
os.Stdout.Write(out)
115+
116+
// One-shot parity check: compare the local answer with GitHub synchronously
117+
// (so the process does not exit before the diff is logged).
118+
if *debugCompare && *method == "GET" && client != nil && res.StatusCode < 400 {
119+
fetch := func(ctx context.Context, p string) (int, []byte, error) {
120+
return proxy.Request(ctx, "GET", p, nil)
121+
}
122+
shadow.New(fetch, nil, owner+"/"+repo).Check(path, out)
123+
}
111124
if res.StatusCode >= 400 {
112125
os.Exit(1)
113126
}

0 commit comments

Comments
 (0)