Skip to content

fix(workflows): minimal-invasive auto-detect integration from project config#1

Merged
markuswondrak merged 2 commits intofix/workflow-integration-auto-detectfrom
copilot/fixworkflow-integration-auto-detect
Apr 30, 2026
Merged

fix(workflows): minimal-invasive auto-detect integration from project config#1
markuswondrak merged 2 commits intofix/workflow-integration-auto-detectfrom
copilot/fixworkflow-integration-auto-detect

Conversation

Copy link
Copy Markdown

Copilot AI commented Apr 30, 2026

The original PR github#2408 correctly fixed the hardcoded default: "copilot" integration input (issue github#2406) but was bloated by ~1500 lines of unrelated Black formatting changes, an unnecessary constants.py, and a post-processing approach that drew review feedback. This revision keeps only the essential logic.

What changed

src/specify_cli/workflows/engine.py

  • Added _INTEGRATION_JSON = ".specify/integration.json" as a module-level constant (replaces the removed constants.py import)
  • Replaced the post-loop if resolved.get("integration") == "auto" block with an inline hook in _resolve_inputs():
    elif "default" in input_def:
        resolved[name] = self._resolve_default(name, input_def["default"])
  • _resolve_default() dispatches to _load_project_integration() only for integration="auto"; all other inputs pass through unchanged
  • _load_project_integration() reads .specify/integration.json and falls back to "copilot" for missing/unreadable/invalid files (backwards-compatible)

tests/test_workflows.py

  • Added TestIntegrationAutoDetect (6 tests) covering: JSON resolution, missing file fallback, explicit input override, malformed JSON, OSError, and whitespace-only value — all as targeted unit tests with no changes to existing tests

workflows/speckit/workflow.yml

  • integration default changed from "copilot""auto"
  • Removed requires.integrations.any static allowlist (incompatible with dynamic resolution)

Removed from original PR

  • src/specify_cli/constants.py (unnecessary new module)
  • All Black formatting changes to src/specify_cli/__init__.py and engine.py
Original prompt

Ziel: PR github#2408 (Branch fix/workflow-integration-auto-detect) minimal-invasiv überarbeiten

Der bestehende PR #2408 auf dem Branch fix/workflow-integration-auto-detect löst das Problem aus Issue github#2406 korrekt, ist aber durch unrelated Style-Änderungen (Black-Formatierung) aufgebläht und enthält unnötige Dateien. Bitte überarbeite den Branch so, dass nur die inhaltlich notwendigen Änderungen enthalten sind.


Was zu tun ist

1. src/specify_cli/__init__.py — alle Änderungen rückgängig machen

Diese Datei enthält ausschließlich Black-Formatierungsänderungen ohne inhaltlichen Mehrwert. Setze sie auf den Stand von main zurück (keine Änderungen an dieser Datei).

2. src/specify_cli/constants.py — Datei entfernen

Diese neue Datei ist nicht notwendig und hat eine Kette von Review-Kommentaren über Import-Seiteneffekte ausgelöst. Den Pfad stattdessen als lokale Konstante direkt in engine.py definieren.

3. src/specify_cli/workflows/engine.py — nur die inhaltliche Logik behalten

Die Implementierung soll so aussehen (alle unrelated Style-Fixes entfernen, nur folgende neue Logik hinzufügen):

a) Den Import von constants.py entfernen:

# Diese Zeile entfernen:
from specify_cli.constants import INTEGRATION_JSON

b) Lokale Konstante am Anfang der Datei (nach den anderen Konstanten) hinzufügen:

_INTEGRATION_JSON = ".specify/integration.json"

c) In _resolve_inputs() den bestehenden Default-Zweig anpassen (innerhalb der Schleife, kein Post-Processing danach):

# Vorher:
resolved[name] = input_def["default"]

# Nachher:
resolved[name] = self._resolve_default(name, input_def["default"])

d) Die Post-Processing-Zeilen entfernen (die nach der Schleife stehen):

# Diese Zeilen entfernen:
# Auto-detect integration from project config when set to "auto"
if resolved.get("integration") == "auto":
    resolved[name] = self._resolve_integration_auto()

e) _resolve_integration_auto() umbenennen und ersetzen durch zwei Methoden:

def _resolve_default(self, name: str, default: Any) -> Any:
    """Resolve special default sentinels against project state.

    For the ``integration`` input, ``"auto"`` resolves to the integration
    recorded in ``.specify/integration.json`` so workflows dispatch to the
    AI the project was actually initialized with.
    """
    if name == "integration" and default == "auto":
        resolved = self._load_project_integration()
        if resolved is not None:
            return resolved
    return default

def _load_project_integration(self) -> str | None:
    """Read the active integration key from ``.specify/integration.json``.

    Returns the stored integration string, or ``None`` when the file is
    missing, unreadable, or does not contain a valid key.
    Falls back to ``"copilot"`` for backwards compatibility when returning None.
    """
    path = self.project_root / _INTEGRATION_JSON
    if not path.is_file():
        return "copilot"
    try:
        data = json.loads(path.read_text(encoding="utf-8"))
    except (OSError, UnicodeDecodeError, json.JSONDecodeError):
        return "copilot"
    if isinstance(data, dict):
        value = data.get("integration", "").strip()
        if value:
            return value
    return "copilot"

Wichtig: Alle anderen Style-Fixes in engine.py (z.B. Zeilenumbrüche in Funktionsaufrufen, Anführungszeichen, etc.) rückgängig machen — die Datei soll abgesehen von den neuen Methoden identisch mit main sein.

4. tests/test_workflows.py — nur neue Tests, keine Style-Fixes

Alle Formatierungsänderungen an bestehenden Tests rückgängig machen. Nur die neue Testklasse TestIntegrationAutoDetect behalten. Diese Klasse soll folgende Tests enthalten:

  • test_integration_auto_default_uses_project_integration"auto" löst zu .specify/integration.json auf
  • test_integration_auto_default_falls_back_to_copilot_when_no_json — kein JSON → Fallback auf "copilot"
  • test_integration_explicit_input_overrides_auto — expliziter --input integration=X gewinnt
  • test_integration_auto_ignores_malformed_integration_json — kaputtes JSON → Fallback auf "copilot"
  • test_integration_auto_falls_back_on_oserror — OSError → Fallback auf "copilot"
  • test_integration_auto_ignores_whitespace_only_value — Whitespace-only Value → Fallback auf "copilot"

Wichtig: Bestehende Tests in test_workflows.py sollen exakt wie in main bleiben — kein Reformat, keine Leerzeilen, keine Importe anpassen.

5. workflows/speckit/workflow.yml — diese Änderungen behalten

integration:
  type: string
  default: "auto"
  prompt: "Integration to use (e.g. claude, copilot, gemini, opencode, or 'auto' to detect from project config)"

Und die requires.integrations.any-Liste entfernen (wie in PR github#2421 gemacht), da eine statische Allowlist mit "auto" nicht sinnvoll kombinierbar ist...

This pull request was created from Copilot chat.

… config

- Add _INTEGRATION_JSON local constant in engine.py
- Replace post-processing _resolve_integration_auto() with inline
  _resolve_default() + _load_project_integration() methods
- Revert all Black style-only changes to engine.py, __init__.py
- Delete unnecessary constants.py
- Add TestIntegrationAutoDetect with 6 tests (no changes to existing tests)
- Update workflow.yml: default 'auto', remove static integrations.any list

Agent-Logs-Url: https://github.com/markuswondrak/spec-kit/sessions/4cb75741-9272-4a13-a90b-cc6cad486967

Co-authored-by: markuswondrak <245696895+markuswondrak@users.noreply.github.com>
Copilot AI changed the title [WIP] Refactor PR #2408 to remove unrelated style changes fix(workflows): minimal-invasive auto-detect integration from project config Apr 30, 2026
Copilot AI requested a review from markuswondrak April 30, 2026 14:54
@markuswondrak markuswondrak marked this pull request as ready for review April 30, 2026 14:55
@markuswondrak markuswondrak merged commit 6727c14 into fix/workflow-integration-auto-detect Apr 30, 2026
8 checks passed
@markuswondrak markuswondrak deleted the copilot/fixworkflow-integration-auto-detect branch April 30, 2026 15:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants