Skip to content

[Bug]: integration_state fails to read .specify/integration.json when saved with a UTF-8 BOM #5591

Backlog

Description

@adityajai119

Summary

_read_integration_json_data() in src/specify_cli/integration_state.py parses .specify/integration.json with json.loads(raw) after reading UTF-8 text without stripping a leading UTF-8 BOM (\ufeff).

If .specify/integration.json is edited or saved on Windows with a UTF-8 BOM (for example via Notepad or Windows PowerShell 5.1 Set-Content -Encoding UTF8 / Out-File -Encoding UTF8), both try_read_integration_json() and try_read_integration_json_with_raw() fail with IntegrationReadError(kind='decode', detail='Unexpected UTF-8 BOM (decode using utf-8-sig): line 1 column 1 (char 0)').

This also diverges from specify_cli.bundles.project.active_integration(), which reads the same .specify/integration.json via bundles/yamlio.py:load_json() and already accepts one leading UTF-8 BOM (#5557).

Reproduction

import tempfile
from pathlib import Path
from specify_cli.integration_state import (
    try_read_integration_json,
    try_read_integration_json_with_raw,
)
from specify_cli.bundles.project import active_integration

with tempfile.TemporaryDirectory() as td:
    root = Path(td)
    (root / ".specify").mkdir()
    payload = '{"version":"1.4.5","integration_state_schema":1,"integration":"claude","default_integration":"claude","installed_integrations":["claude"]}\n'
    (root / ".specify" / "integration.json").write_bytes(b"\xef\xbb\xbf" + payload.encode("utf-8"))
    print("active_integration:", active_integration(root))
    print("try_read_integration_json:", try_read_integration_json(root))
    print("try_read_integration_json_with_raw:", try_read_integration_json_with_raw(root))

Observed on main (f201054):

active_integration: claude
try_read_integration_json: (None, IntegrationReadError(kind='decode', detail='Unexpected UTF-8 BOM (decode using utf-8-sig): line 1 column 1 (char 0)', schema=None))
try_read_integration_json_with_raw: (None, None, IntegrationReadError(kind='decode', detail='Unexpected UTF-8 BOM (decode using utf-8-sig): line 1 column 1 (char 0)', schema=None))

Expected behavior

Accept a single leading UTF-8 BOM in _read_integration_json_data() (matching bundles/yamlio.py), while still reporting IntegrationReadError(kind='decode') for double BOMs, BOM-only empty files, or malformed JSON after a BOM, and kind='not_object' for non-object JSON after a BOM.

Disclosure

This issue was discovered and filed by an AI agent (OpenCode, model: Gemini 4 Neon, autonomous mode) acting on behalf of adityajai119; reproduction was verified directly against main (f201054).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions