Commit graph

17 commits

Author SHA1 Message Date
Harry Miller
397eb4d721
fix(ado): use date-only format for WIQL ChangedDate queries (#3345)
Thanks @harry-miller-trimble for the clean fix and thorough test updates!
2026-04-20 13:05:34 -07:00
Harry Miller
33cab03193
fix: recognize ado:NNNNN shorthand in IsExternalRef and ExtractIdentifier (#2966)
* fix: recognize ado:NNNNN shorthand in IsExternalRef and ExtractIdentifier

IsExternalRef and ExtractIdentifier only matched full ADO URLs
(/_workitems/edit/\d+), but BuildExternalRef produces ado:NNNNN
shorthand when org/project config is unavailable. This caused the
sync engine to treat existing beads as new, creating duplicate ADO
work items instead of updating existing ones.

Fixes harry-miller-trimble/beads#28

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* fix: add shorthand ref support to GitHub/GitLab trackers, tighten ado:0

Address PR #2966 review feedback:

- GitHub tracker: add ghShorthandPattern (github:{id}) to IsExternalRef
  and ExtractIdentifier, fixing the same duplicate-creation bug as ADO
- GitLab tracker: add glShorthandPattern (gitlab:{id}) to IsExternalRef
  and ExtractIdentifier, fixing the same duplicate-creation bug as ADO
- ADO tracker: tighten regex from ^ado:(\d+)$ to ^ado:([1-9]\d*)$ to
  reject ado:0 which is invalid in practice
- Add test cases for shorthand format in all three trackers

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-02 19:20:30 -07:00
Steve Yegge
73c66ad3a7
Merge pull request #2814 from harry-miller-trimble/feat/tracker-hardening-and-core
feat: tracker hardening, graph integrity, and ready --explain
2026-03-30 20:41:05 -07:00
Steve Yegge
ef1cd3d095
Merge pull request #2912 from harry-miller-trimble/fix/ado-sync-closed-state
fix(ado): create work items in initial state then transition to target
2026-03-30 20:28:29 -07:00
beads/crew/emma
ae77bd43d9 fix: replace fragile string matching with typed APIError for HTTP status checks
Introduce APIError type in client.go that carries the HTTP status code,
replacing fmt.Errorf-based error strings. Update statetransition.go and
reconcile.go to use errors.As instead of strings.Contains for status
code detection, making the error handling robust against message changes.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-30 20:28:13 -07:00
Steve Yegge
5a3fe23bae
Merge pull request #2911 from harry-miller-trimble/fix/ado-sync-severity
fix(ado): set Severity field for Bug work items during sync
2026-03-30 20:22:02 -07:00
Harry
8cd24769fc fix: use proper RFC3339 timezone in WIQL date formatting (bd-wz8)
The WIQL date format string used a literal 'Z' character instead of Go's
proper Z07:00 timezone placeholder. While .UTC() masked the issue for UTC
inputs, the format was fragile — if a non-UTC time were passed without
.UTC(), the output would claim UTC (literal Z) while containing local time.

Changes:
- Extract formatWIQLDate() helper that encapsulates UTC conversion + RFC3339
  formatting, making it impossible to forget either step
- Replace inline format string in buildPullWIQLMulti() with the new helper
- Fix same pattern in mol_last_activity.go (display output)
- Add TestFormatWIQLDate with 7 cases: UTC, non-UTC offsets, nanosecond
  truncation, day boundary rollovers, and Z-suffix invariant assertion
- Add non-UTC test case to TestBuildPullWIQL for end-to-end coverage

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-03-30 12:31:26 -07:00
Harry
9e34b07a4b fix(ado): create work items in initial state then transition to target
When pushing issues to ADO, CreateIssue now handles non-initial states
(e.g., Closed, Active, Resolved) by:

1. Stripping the target state from creation fields when it is not a
   valid initial state (New, To Do, Proposed)
2. Creating the work item without specifying state (ADO assigns default)
3. Transitioning to the target state via UpdateWorkItem — first tries
   a direct update, then walks through known intermediate states if
   the direct transition is rejected (400)

Includes default transition paths for Agile, Scrum, and CMMI process
templates covering Bug, Task, User Story, Epic, Feature, Issue, PBI,
and Requirement work item types.

Fixes: bd-cl7

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-03-30 12:25:32 -07:00
Harry
163c27bc68 fix: set ADO Severity field for Bug work items during sync
ADO Bug work items require a Severity field (Microsoft.VSTS.Common.Severity),
but bd ado sync --push-only was not setting it, causing TF401320 rule errors.

Changes:
- Add FieldSeverity constant for Microsoft.VSTS.Common.Severity
- Add SeverityForBug() to map beads priority to ADO severity values:
  P0→"1 - Critical", P1→"2 - High", P2→"3 - Medium", P3/P4→"4 - Low"
- Set Severity in IssueToTracker only for Bug-type work items
- Preserve severity in metadata for round-trip fidelity (pull→push)
- Metadata-restored severity takes precedence over computed value

Fixes: bd-4ju

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-03-30 12:22:26 -07:00
Harry
860ef5969b lint: suppress gosec G404 for retry jitter (math/rand is fine for backoff)
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-03-30 09:15:53 -07:00
Harry
73f786ffb8 github,ado: fix Retry-After jitter in retry loops
Apply the same fix as the Jira client: only add jitter to our own
exponential backoff delays, not to server-mandated Retry-After values.
Adding jitter to Retry-After could violate rate limit contracts by
waiting less than the server-specified duration.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-03-30 09:15:52 -07:00
Harry
5708a36c45 Fix ADO Init tests leaking environment variables
TestTracker_InitMissingPAT, InitMissingOrg, and InitMissingProject were
not isolating from environment variables. When AZURE_DEVOPS_PAT is set
in the environment (common in CI and dev), getConfig falls through to
os.Getenv and the PAT check passes, causing the test to hit the org
validation instead and fail.

Fix: Use t.Setenv to clear all ADO env vars in tests that assert
specific missing-config errors. t.Setenv automatically restores the
original values after the test.

Fixes: bd-czk

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-03-30 09:13:17 -07:00
Harry
00b78da749 Add retry logic to Jira client and jitter to all tracker HTTP clients
- Add retry with exponential backoff to Jira doRequest (was single-attempt)
- Add MaxRetries, RetryDelay, MaxResponseSize constants to jira/types.go
- Add response body size limit via io.LimitReader to Jira client
- Handle permanent errors (400/401/403/404) without retry
- Parse Retry-After header for rate-limited responses
- Add jitter (0-50% of delay) to backoff in all 5 tracker clients:
  GitHub, GitLab, Linear, ADO, and Jira
- Guard rand.Int64N against zero delay to prevent panics
- Add retry tests: 429, 503, no-retry-on-400, max-retries-exceeded

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-03-30 09:11:19 -07:00
Harry
3ae2ef3a5a feat: multi-project/team support for Linear, Jira, and ADO
Add support for syncing issues across multiple projects/teams in all
three tracker integrations, with shared infrastructure to avoid
duplicating logic.

Shared infrastructure (internal/tracker/multiproject.go):
- ParseCommaSeparated: splits comma-separated config values
- DeduplicateStrings: removes duplicates preserving order
- ResolveProjectIDs: config precedence (CLI > plural > singular)

Linear (closes #2791):
- Tracker: map[string]*Client with per-team routing
- FetchIssues iterates all teams, deduplicates by issue ID
- UpdateIssue routes to owning team via FetchIssueByIdentifier
- Config: linear.team_ids / LINEAR_TEAM_IDS + --team flag

Jira:
- projectKey string → projectKeys []string
- FetchIssues uses JQL IN clause (single query, no iteration)
- Config: jira.projects / JIRA_PROJECTS + --project flag

ADO:
- project string → projects []string
- WIQL uses TeamProject IN clause (single query)
- Config: ado.projects / AZURE_DEVOPS_PROJECTS + --project flag

All singular config keys remain supported for backward compatibility.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-03-28 13:40:39 -07:00
Harry
2d0762e891 fix: ADO dependency links not imported due to ID format mismatch
ExtractLinkDeps stored bare numeric IDs (e.g., "123") in
FromExternalID/ToExternalID, but the sync engine's createDependencies
looks up issues via GetIssueByExternalRef which expects full web URLs
(e.g., "https://dev.azure.com/org/proj/_workitems/edit/123").

The mismatch caused all dependency lookups to return nil, silently
skipping every dependency creation. After pulling 800+ ADO items,
dependency_count was 0 for all beads.

Fix: Use buildExternalRef (for the source work item) and a new
apiURLToWebURL helper (for relation target URLs) to produce web URLs
that match the external_ref format stored in the database.

Jira has a separate gap: its IssueToBeads returns no Dependencies at
all (the fieldmapper is hardcoded with no link extraction). That needs
its own fix since Jira link types differ from ADO.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-03-23 18:03:02 -07:00
Harry
d8fed04058 fix: custom type_map config ignored for ADO and Jira trackers
readMappingConfig used a hardcoded key list (bug, feature, task, epic,
chore) which silently dropped custom types like "story". Users who
set ado.type_map.story="User Story" with types.custom=story would
still see User Stories mapped to "feature" on pull because the config
was never loaded.

Jira had the same bug but worse: jira.type_map.* was documented in
CONFIG.md but the fieldmapper was entirely hardcoded with no config
reading at all.

Fix for both trackers:
- ADO: Replace readMappingConfig (hardcoded key list) with
  readMappingConfigByPrefix (prefix scan via GetAllConfig), matching
  the pattern Jira already uses for status_map
- Jira: Add typeMap field to fieldmapper, load jira.type_map.* keys
  via the same GetAllConfig prefix scan used for jira.status_map.*,
  and check custom map before hardcoded defaults in TypeToBeads/
  TypeToTracker

Linear and GitHub trackers are not affected — they already use
dynamic config loading for type mappings.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-03-23 18:03:02 -07:00
beads/crew/emma
39ab50d447 feat(ado): add Azure DevOps work item tracker package
Add the internal/ado package implementing tracker.IssueTracker for Azure
DevOps. Provides bidirectional work item sync via the ADO REST API.

Core components:
- types.go: ADO API types, SecretString with redaction, field constants
- client.go: HTTP client with Basic auth, retry, WIQL query builder
- fieldmapper.go: configurable status/type/priority mapping
- mapping.go: bidirectional IssueToBeads/IssueToTracker conversion
- richtext.go: HTML<>Markdown conversion (goldmark + bluemonday)
- tracker.go: tracker.IssueTracker implementation with init() registration
- bootstrap.go: 4-tier deduplication for first sync
- reconcile.go: deletion detection via periodic reconciliation scan
- links.go: bidirectional link sync with direction normalization

Includes full test suite (218 tests, 92.8% coverage).

Fixes applied during fix-merge:
- errors.New() → fmt.Errorf() to match project conventions (6 instances)
- Added gosec nolint for configured API endpoint SSRF false positive

Co-Authored-By: Harry Miller <harry_miller@trimble.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-19 14:34:28 -07:00