fix(github): restore PR sync context (#2916)
This commit is contained in:
@@ -0,0 +1,110 @@
|
||||
---
|
||||
spec: docs/specs/pr-outcome-attribution/spec.md
|
||||
created: 2026-08-22
|
||||
status: implemented
|
||||
---
|
||||
|
||||
# Implementation Plan: Restore GitHub PR Sync Context
|
||||
|
||||
## Overview
|
||||
|
||||
The pull-request outcome change extracted the final sync write into a helper.
|
||||
The helper still uses `taskID` and `status.PR`, but its signature does not
|
||||
receive either value. As a result, the GitHub package does not compile.
|
||||
|
||||
Pass the task and pull-request context into the helper. Keep the existing order:
|
||||
persist the task PR, reconcile the comparison target, then publish the committed
|
||||
row when semantic data changed.
|
||||
|
||||
## Confirmed Root Cause
|
||||
|
||||
Commit `9178780ba` extracted `persistAndPublishTaskPRSync` from `SyncTaskPR`.
|
||||
The extracted body kept this call:
|
||||
|
||||
```go
|
||||
s.reconcileComparisonTargetFromSync(ctx, taskID, status.PR)
|
||||
```
|
||||
|
||||
The new helper signature does not receive `taskID` or `status`. The focused
|
||||
backend build therefore stops with these compiler errors:
|
||||
|
||||
```text
|
||||
internal/github/service_pr_watch.go:1024:43: undefined: taskID
|
||||
internal/github/service_pr_watch.go:1024:51: undefined: status
|
||||
```
|
||||
|
||||
Use this reproduction command when the default Go cache is read-only:
|
||||
|
||||
```bash
|
||||
cd apps/backend && GOCACHE=/tmp/kandev-go-build-cache make build-kandev
|
||||
```
|
||||
|
||||
## Backend
|
||||
|
||||
### Sync writer context
|
||||
|
||||
Update `apps/backend/internal/github/service_pr_watch.go`:
|
||||
|
||||
- Add the task ID and pull-request payload to
|
||||
`persistAndPublishTaskPRSync`.
|
||||
- Pass `taskID` and `status.PR` from `SyncTaskPR`.
|
||||
- Pass `tp.TaskID` and `status.PR` from unwatched lifecycle reconciliation.
|
||||
- Keep comparison-target reconciliation after `UpdateTaskPR` succeeds.
|
||||
- Keep event publication after comparison-target reconciliation.
|
||||
- Return immediately when `UpdateTaskPR` fails.
|
||||
|
||||
### Regression coverage
|
||||
|
||||
Add `apps/backend/internal/github/service_comparison_target_sync_test.go`.
|
||||
Use a comparison-target observer that reads the stored row during its callback.
|
||||
The test proves that the write occurs first and that the observer receives the
|
||||
correct task and pull-request identity.
|
||||
|
||||
Update the direct helper call in
|
||||
`apps/backend/internal/github/service_pr_outcome_sync_test.go`. Pass explicit
|
||||
task and pull-request context through the helper contract.
|
||||
|
||||
Update the unwatched lifecycle caller in
|
||||
`apps/backend/internal/github/service_pr_unwatched.go` with the same context.
|
||||
|
||||
## Tests
|
||||
|
||||
- **What:** the GitHub package compiles after the helper receives its required
|
||||
context.
|
||||
**File:** `apps/backend/internal/github/service_pr_watch.go`.
|
||||
**How:** compile the package through the focused Go test command.
|
||||
- **What:** a normal sync persists the task PR before comparison reconciliation.
|
||||
**File:** `apps/backend/internal/github/service_comparison_target_sync_test.go`.
|
||||
**How:** use a fake observer that reads the stored row in its callback.
|
||||
- **What:** the helper still publishes the committed row after a stale write.
|
||||
**File:** `apps/backend/internal/github/service_pr_outcome_sync_test.go`.
|
||||
**How:** run the existing deterministic stale-writer regression test.
|
||||
|
||||
## Verification Results
|
||||
|
||||
- RED: `GOCACHE=/tmp/kandev-go-build-cache go test ./internal/github -run
|
||||
TestSyncTaskPR_PersistsBeforeComparisonTargetReconciliation` failed at the
|
||||
expected undefined `taskID` and `status` compiler errors.
|
||||
- GREEN: the focused regression test passed.
|
||||
- Targeted tests: the regression test and stale-writer test passed.
|
||||
- Backend build: `GOCACHE=/tmp/kandev-go-build-cache make build` passed.
|
||||
- Formatting: `gofmt -w` completed for all changed Go files.
|
||||
- `git diff --check` passed.
|
||||
- Build output was written to ignored files under `apps/backend/bin`.
|
||||
- No temporary source files or E2E assets were created.
|
||||
|
||||
## Implementation Waves And Parallel Candidates
|
||||
|
||||
Wave 1:
|
||||
|
||||
- [x] [task-01-restore-sync-context](task-01-restore-sync-context.md) (done)
|
||||
|
||||
The task is sequential because the source and tests share one package contract.
|
||||
|
||||
## Risks And Out Of Scope
|
||||
|
||||
- The fix does not change pull-request field sourcing or storage schemas.
|
||||
- The fix does not change comparison-target matching rules.
|
||||
- The fix does not change event payloads or event ordering.
|
||||
- The fix does not change the root Makefile output suppression.
|
||||
- The read-only default Go cache remains an environment concern.
|
||||
@@ -0,0 +1,100 @@
|
||||
---
|
||||
id: "01-restore-sync-context"
|
||||
title: "Restore GitHub PR sync context"
|
||||
status: done
|
||||
wave: 1
|
||||
depends_on: []
|
||||
plan: "plan.md"
|
||||
spec: "../../specs/pr-outcome-attribution/spec.md"
|
||||
---
|
||||
|
||||
# Task 01: Restore GitHub PR Sync Context
|
||||
|
||||
## Intent
|
||||
|
||||
Restore the missing task and pull-request context in the final sync helper.
|
||||
Preserve the existing persistence, reconciliation, and publication order.
|
||||
|
||||
## Acceptance
|
||||
|
||||
- `apps/backend/internal/github` compiles without undefined identifiers.
|
||||
- `SyncTaskPR` persists the task PR before comparison-target reconciliation.
|
||||
- The comparison observer receives the same task ID and PR identity as the sync.
|
||||
- Existing stale-writer event behavior remains unchanged.
|
||||
|
||||
## Red Test First
|
||||
|
||||
Add `TestSyncTaskPR_PersistsBeforeComparisonTargetReconciliation` in
|
||||
`service_comparison_target_sync_test.go`. The current package must fail to
|
||||
compile because the helper does not receive `taskID` or `status.PR`.
|
||||
|
||||
## Implementation
|
||||
|
||||
- Extend `persistAndPublishTaskPRSync` with `taskID string` and `pr *PR`.
|
||||
- Pass `taskID` and `status.PR` from `SyncTaskPR`.
|
||||
- Pass `tp.TaskID` and `status.PR` from unwatched lifecycle reconciliation.
|
||||
- Use those parameters for `reconcileComparisonTargetFromSync`.
|
||||
- Update direct helper calls in existing tests.
|
||||
- Do not change storage, reconciliation, or event behavior.
|
||||
|
||||
## Files Likely Touched
|
||||
|
||||
- `apps/backend/internal/github/service_pr_watch.go`
|
||||
- `apps/backend/internal/github/service_pr_unwatched.go`
|
||||
- `apps/backend/internal/github/service_comparison_target_sync_test.go`
|
||||
- `apps/backend/internal/github/service_pr_outcome_sync_test.go`
|
||||
- `docs/plans/github-pr-sync-context-regression/plan.md`
|
||||
- `docs/plans/github-pr-sync-context-regression/task-01-restore-sync-context.md`
|
||||
|
||||
## Dependencies
|
||||
|
||||
None.
|
||||
|
||||
## Parallelism
|
||||
|
||||
`sequential`. The source and tests share one helper contract.
|
||||
|
||||
## Inputs
|
||||
|
||||
- `docs/specs/pr-outcome-attribution/spec.md`, section `Sync writer`
|
||||
- `docs/specs/platform/workspace-git-status.md`, section
|
||||
`Repository-qualified comparison targets`
|
||||
- `docs/decisions/2026-08-19-repository-qualified-comparison-targets.md`
|
||||
|
||||
## Verification
|
||||
|
||||
Run these commands from the repository root:
|
||||
|
||||
```bash
|
||||
cd apps/backend && \
|
||||
GOCACHE=/tmp/kandev-go-build-cache go test ./internal/github -run 'TestSyncTaskPR_PersistsBeforeComparisonTargetReconciliation|TestPersistAndPublishTaskPRSync_PublishesReReadValueNotStaleInMemoryOne' && \
|
||||
GOCACHE=/tmp/kandev-go-build-cache make build
|
||||
```
|
||||
|
||||
Then run this command from the repository root:
|
||||
|
||||
```bash
|
||||
git diff --check
|
||||
```
|
||||
|
||||
## Output Contract
|
||||
|
||||
Report the changed files, exact command results, blockers, and remaining risks.
|
||||
Update this task and `plan.md` in the same conversation.
|
||||
|
||||
## Results
|
||||
|
||||
- RED: `GOCACHE=/tmp/kandev-go-build-cache go test ./internal/github -run
|
||||
TestSyncTaskPR_PersistsBeforeComparisonTargetReconciliation` failed with the
|
||||
expected undefined `taskID` and `status` compiler errors.
|
||||
- GREEN: `GOCACHE=/tmp/kandev-go-build-cache go test ./internal/github -run
|
||||
TestSyncTaskPR_PersistsBeforeComparisonTargetReconciliation` passed.
|
||||
- Targeted regression command passed:
|
||||
`GOCACHE=/tmp/kandev-go-build-cache go test ./internal/github -run
|
||||
"TestSyncTaskPR_PersistsBeforeComparisonTargetReconciliation|TestPersistAndPublishTaskPRSync_PublishesReReadValueNotStaleInMemoryOne"`.
|
||||
- Backend build passed:
|
||||
`GOCACHE=/tmp/kandev-go-build-cache make build`.
|
||||
- `gofmt -w` completed for all changed Go files.
|
||||
- `git diff --check` passed.
|
||||
- Build output was written to ignored files under `apps/backend/bin`.
|
||||
- No temporary source files or E2E assets were created.
|
||||
Reference in New Issue
Block a user