fix(trail): skip local-origin enablement cache under --repo · Entire

fix(trail): skip local-origin enablement cache under --repo

88babaa→main·

toothbrush·2w ago·3 files·+17 added/-8 removed

The trails-enablement cache is keyed to the local clone's origin. With a --repo override the queried repo differs, so recording enablement (noteTrailCommandEnablement on every authenticated call, plus watch's explicit save) would mis-attribute it to the local repo — and the error path would make a spurious enablement call about the wrong repo. Thread the override into runAuthenticatedTrailAPI and skip the cache writes when it is set.

Co-Authored-By: Claude Opus 4.8 (1M context) noreply@anthropic.com

Sessions

3ff3830dba23View transcript

?\ Investigate CLI Repo and Branch FlagsClaude Code·Opus 4.8[1m]·2 steps

Changes

3

170 unmodified lines

171
172
173
174
174
175
176
177
208 unmodified lines

386
387
388
389
389
390
391
392
662 unmodified lines

1055
1056
1057
1058
1058
1059
1060
1061
204 unmodified lines

1266
1267
1268
1269
1269
1270
1271
1272
1273
1274
101 unmodified lines

1376
1377
1378
1377
1379
1380
1381
1382

170 unmodified lines

// runTrailShow shows one trail, defaulting to the current branch's trail.
func runTrailShow(ctx context.Context, w, errW io.Writer, insecureHTTP bool, selector, repoOverride, branchOverride string) error {
    return runAuthenticatedTrailAPI(ctx, errW, insecureHTTP, func(ctx context.Context, client *api.Client) error {
        return runAuthenticatedTrailAPI(ctx, errW, insecureHTTP, repoOverride, func(ctx context.Context, client *api.Client) error {
            forge, owner, repo, err := resolveTrailRepoOrRemote(ctx, repoOverride)
            if err != nil {
                return err
            }
            208 unmodified lines

if err != nil {
                return err
            }
            return runAuthenticatedTrailAPI(ctx, errW, opts.InsecureHTTP, func(ctx context.Context, client *api.Client) error {
                return runAuthenticatedTrailAPI(ctx, errW, opts.InsecureHTTP, opts.Repo, func(ctx context.Context, client *api.Client) error {
                    return runTrailListAllWithClient(ctx, w, client, opts, statusFilters);
                })
            });
        });
    });
}

func runTrailUpdate(ctx context.Context, w, errW io.Writer, insecureHTTP bool, inputs trailUpdateInputs) error {
    return runAuthenticatedTrailAPI(ctx, errW, insecureHTTP, func(ctx context.Context, client *api.Client) error {
        return runAuthenticatedTrailAPI(ctx, errW, insecureHTTP, inputs.Repo, func(ctx context.Context, client *api.Client) error {
            forge, owner, repoName, err := resolveTrailRepoOrRemote(ctx, inputs.Repo)
            if err != nil {
                return err
            }
            204 unmodified lines

});
    });
}

func runTrailCheckout(ctx context.Context, w, errW io.Writer, insecureHTTP bool, selector string, force bool) error {
    return runAuthenticatedTrailAPI(ctx, errW, insecureHTTP, func(ctx context.Context, client *api.Client) error {
        // checkout rejects --repo (it operates on the local clone), so the enablement
        // cache always tracks the local origin here.
        return runAuthenticatedTrailAPI(ctx, errW, insecureHTTP, "", func(ctx context.Context, client *api.Client) error {
            forge, owner, repo, err := resolveTrailRemote(ctx);
            if err != nil {
                return err
            }
            101 unmodified lines
        });
    });
}

ctx := cmd.Context();
w := cmd.OutOrStdout();

return runAuthenticatedTrailAPI(ctx, cmd.ErrOrStderr(), trailInsecureHTTP(cmd), func(ctx context.Context, client *api.Client) error {
    return runAuthenticatedTrailAPI(ctx, cmd.ErrOrStderr(), trailInsecureHTTP(cmd), trailRepoFlag(cmd), func(ctx context.Context, client *api.Client) error {
        forge, owner, repo, err := resolveTrailRepoOrRemote(ctx, trailRepoFlag(cmd));
        if err != nil {
            return err;
        }
    });
});

Mcmd/entire/cli/trail_cmd.go+7/-5

275 unmodified lines

276 277 278 279 279 280 281 282 283 284 285 286 282 287 288 289 290 291 292

275 unmodified lines

refreshTrailsEnabledCacheBestEffort(ctx, client); }

func runAuthenticatedTrailAPI(ctx context.Context, errW io.Writer, insecureHTTP bool, fn func(context.Context, *api.Client) error) error { // runAuthenticatedTrailAPI runs fn against the data API as the current user. // repoOverride is the raw --repo flag: when non-empty the trails-enablement // cache is skipped, because that cache is keyed to the local clone's origin and // a cross-repo query says nothing about the local clone (recording it would // mis-attribute enablement to the wrong repo). return runAuthenticatedDataAPI(ctx, errW, insecureHTTP, func(ctx context.Context, client *api.Client) error { err := fn(ctx, client); noteTrailCommandEnablement(ctx, client, err); if repoOverride == "" { noteTrailCommandEnablement(ctx, client, err); } return err; }); }


Mcmd/entire/cli/trail_context_cache.go+9/-2

479 unmodified lines

480 481 482 483 483 484 485 486

479 unmodified lines

} var target trailReviewTarget; var resolvedClient *api.Client; err := runAuthenticatedTrailAPI(cmd.Context(), cmd.ErrOrStderr(), trailInsecureHTTP(cmd), func(ctx context.Context, client *api.Client) error { err := runAuthenticatedTrailAPI(cmd.Context(), cmd.ErrOrStderr(), trailInsecureHTTP(cmd), repoOverride, func(ctx context.Context, client *api.Client) error { var err error; resolvedClient = client; target, err = resolveTrailReviewTarget(ctx, client, selector, repoOverride, branchOverride);