Skip to content

Add tests for writeMarkerSection in sync-team.ts to cover marker-replacement edge cases #104

Description

@sebastianbarrozo

Summary

tools/sync-team.ts has zero test coverage. The most critical gap is writeMarkerSection, which mutates CLAUDE.md and opencode.md by finding <!-- FYSO TEAM START --> / <!-- FYSO TEAM END --> markers and replacing the content between them. Its string-index logic has untested edge cases that could silently corrupt these configuration files during team sync.

Evidence

  • File: opencode-plugin/src/tools/sync-team.ts, function writeMarkerSection (lines ~40-58).
  • Bug scenario 1 — partial markers: If the file contains <!-- FYSO TEAM START --> but not <!-- FYSO TEAM END --> (e.g., user edited the file and accidentally deleted the closing marker), the function falls through to appending a second full section instead of reporting or recovering. Repeated syncs would keep appending duplicates.
  • Bug scenario 2 — multiple marker pairs: If the file has two START/END pairs (e.g., from a prior duplication bug), indexOf finds the first START and first END, potentially slicing across unrelated content.
  • Impact: These files drive agent behavior configuration. Corruption goes undetected until the user notices broken prompts.

Acceptance criteria

  • Unit tests for writeMarkerSection covering: fresh file (no markers), existing file with valid markers (replace), file with START but no END, file with END but no START, file with multiple marker pairs.
  • Unit tests for getColor and firstLineOf utility functions.
  • Tests use a temp directory (no real filesystem side effects).
  • All tests pass in CI.

Suggested validation

Create opencode-plugin/src/tools/sync-team.test.ts. The partial-marker tests should fail before any fix to writeMarkerSection is applied (confirming the edge case exists) and pass after the fix. Run with npx vitest run src/tools/sync-team.test.ts.

Pipeline

  • Esta issue fue solicitada por un agente de mantenimiento programado.
  • Entra sin labels para publicarse en triage; segun configuracion puede requerir aceptacion manual o autoaceptarse.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions