Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions fixos/cli/cleanup_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ def _single_service_target(service_name: str, scanner) -> dict | None:


def _cleanup_single_service(
service_name: str, scanner, json_output: bool, dry_run: bool
service_name: str, scanner, json_output: bool, dry_run: bool, yes: bool = False
) -> None:
"""Handle cleanup of a single specific service."""
target = _single_service_target(service_name, scanner)
Expand Down Expand Up @@ -630,7 +630,9 @@ def _cleanup_single_service(
)
)
click.echo(f" {target['cleanup_command']}")
if not click.confirm(f"Wykonać ograniczone czyszczenie {target['name']}?"):
if not yes and not click.confirm(
f"Wykonać ograniczone czyszczenie {target['name']}?"
):
click.echo("Anulowano.")
return

Expand Down Expand Up @@ -2460,7 +2462,9 @@ def _dispatch_scanner_route(req: CleanupCliRequest, route: CleanupRouteDecision)
if route.action_name == "flatpak":
_cleanup_flatpak_detailed(scanner, req.json_output, req.dry_run)
else:
_cleanup_single_service(route.action_name, scanner, req.json_output, req.dry_run)
_cleanup_single_service(
route.action_name, scanner, req.json_output, req.dry_run, yes=req.yes
)
else:
_run_service_plan_route(req, route, scanner)

Expand Down
16 changes: 14 additions & 2 deletions fixos/cli/dns_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from __future__ import annotations

import json
import sys

import click

Expand Down Expand Up @@ -89,9 +90,20 @@ def dns(
click.echo(click.style("\nPlan naprawy DNS:", fg="cyan", bold=True))
for item in plan:
click.echo(f" - {item['description']}")
should_execute = click.confirm("Wykonać powyższy plan naprawy DNS?", default=True)
if not sys.stdin.isatty():
click.echo(
click.style(
"Tryb nieinteraktywny wymaga flagi --yes do wykonania naprawy DNS.",
fg="yellow",
)
)
should_execute = False
else:
should_execute = click.confirm("Wykonać powyższy plan naprawy DNS?", default=True)
if should_execute:
repair_results = apply_dns_repair(plan, dry_run=dry_run)
repair_results = apply_dns_repair(
plan, dry_run=dry_run, non_interactive=yes or not sys.stdin.isatty()
)

if as_json:
payload = result.to_dict()
Expand Down
36 changes: 26 additions & 10 deletions fixos/plugins/builtin/dns.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import shutil
import socket
import subprocess
import sys
import time
from collections.abc import Sequence
from pathlib import Path
Expand Down Expand Up @@ -276,20 +277,32 @@ def build_repair_plan(
return plan


def _with_non_interactive_sudo(cmd: list[str], *, non_interactive: bool) -> list[str]:
"""Add ``-n`` to ``sudo`` invocations in non-interactive mode so sudo fails fast."""
if non_interactive and cmd and cmd[0] == "sudo" and "-n" not in cmd[1:3]:
return ["sudo", "-n", *cmd[1:]]
return list(cmd)


def apply_dns_repair(
plan: Sequence[dict[str, Any]], dry_run: bool = False
plan: Sequence[dict[str, Any]],
dry_run: bool = False,
*,
non_interactive: bool | None = None,
) -> list[dict[str, Any]]:
"""Execute or simulate a DNS repair plan built by ``build_repair_plan``."""
is_non_interactive = (not sys.stdin.isatty()) if non_interactive is None else bool(non_interactive)
results: list[dict[str, Any]] = []
for item in plan:
step = str(item.get("step", "unknown"))
cmd = [str(part) for part in item.get("command", [])]
raw_cmd = [str(part) for part in item.get("command", [])]
cmd = _with_non_interactive_sudo(raw_cmd, non_interactive=is_non_interactive)
if dry_run:
results.append(
{
"step": step,
"description": item.get("description", ""),
"command": " ".join(cmd),
"command": " ".join(raw_cmd),
"ok": True,
"dry_run": True,
"output": "dry-run",
Expand All @@ -311,9 +324,12 @@ def apply_dns_repair(
}
)
continue
tee_cmd = _with_non_interactive_sudo(
["sudo", "tee", str(item["path"])], non_interactive=is_non_interactive
)
try:
proc = subprocess.run(
["sudo", "tee", str(item["path"])],
tee_cmd,
input=str(item["content"]),
capture_output=True,
text=True,
Expand All @@ -329,7 +345,7 @@ def apply_dns_repair(
{
"step": step,
"description": item.get("description", ""),
"command": f"sudo tee {item['path']}",
"command": " ".join(tee_cmd),
"ok": ok,
"dry_run": False,
"output": output,
Expand Down Expand Up @@ -388,7 +404,7 @@ def diagnose(self) -> DiagnosticResult:
f"Plik {self.resolv_conf_path} nie zawiera żadnego wpisu nameserver."
),
suggestion="Uruchom deterministyczną naprawę DNS przez `fixos dns --fix`.",
command="fixos dns --fix",
command="fixos dns --fix --yes",
)
)

Expand All @@ -408,7 +424,7 @@ def diagnose(self) -> DiagnosticResult:
"Dodaj niezawodne serwery DNS (1.1.1.1, 8.8.8.8) z zachowaniem "
"lokalnej domeny przez `fixos dns --fix`."
),
command="fixos dns --fix",
command="fixos dns --fix --yes",
data={"total_timeouts": total_timeouts},
)
)
Expand Down Expand Up @@ -448,7 +464,7 @@ def diagnose(self) -> DiagnosticResult:
"Skonfiguruj 1.1.1.1 i 8.8.8.8 przed DNS routera, zachowując "
"rozwiązywanie domeny lokalnej: `fixos dns --fix`."
),
command="fixos dns --fix",
command="fixos dns --fix --yes",
data={"devices": [link["device"] for link in router_only_links]},
)
)
Expand All @@ -463,7 +479,7 @@ def diagnose(self) -> DiagnosticResult:
severity=Severity.CRITICAL,
description=f"Błąd rozwiązywania nazwy {probe['host']}: {probe['error']}",
suggestion="Uruchom `fixos dns --fix` aby odświeżyć i naprawić konfigurację DNS.",
command="fixos dns --fix",
command="fixos dns --fix --yes",
data=probe,
)
)
Expand All @@ -480,7 +496,7 @@ def diagnose(self) -> DiagnosticResult:
f"(próg ostrzeżenia: {LATENCY_WARNING_MS:.0f} ms)."
),
suggestion="Przełącz DNS na 1.1.1.1 / 8.8.8.8 przez `fixos dns --fix`.",
command="fixos dns --fix",
command="fixos dns --fix --yes",
data=probe,
)
)
Expand Down
1 change: 1 addition & 0 deletions project/TICKETS.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,4 +181,5 @@ This file indexes governance tickets without taking ownership of
| **ticket-183** | [`README.md`](./ticket-183/README.md) | - | - | - | - | - |
| **ticket-184** | [`README.md`](./ticket-184/README.md) | - | - | - | - | - |
| **ticket-185** | [`README.md`](./ticket-185/README.md) | - | - | - | - | - |
| **ticket-186** | [`README.md`](./ticket-186/README.md) | - | - | - | - | - |
<!-- AUTO:TICKET_INDEX:END -->
19 changes: 19 additions & 0 deletions project/ticket-186/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Ticket 186: Fix non-interactive --yes handling in cleanup_cmd and dns_cmd/dns plugin

- **ID**: ticket-186
- **Owner**: agent:antigravity (SESSION_EXECUTION_AUTHORIZATION from user request)
- **Status**: IN_PROGRESS
- **Workflow state**: EDIT
- **Created**: 2026-11-23

## Goal and scope

Fix two live non-interactive hangs observed during autonomous `fixos` execution:
1. Pass `yes=req.yes` to `_cleanup_single_service` in `fixos/cli/cleanup_cmd.py` so `fixos cleanup -c docker --yes` skips `click.confirm(...)`.
2. Guard `fixos dns --fix` against hanging in non-TTY / `fixos auto --yes` mode by refusing interactive `click.confirm` without `--yes`, injecting `sudo -n` in `apply_dns_repair` when non-interactive, and emitting `fixos dns --fix --yes` from `fixos/plugins/builtin/dns.py`.

## Acceptance criteria

- [x] AC-01: `fixos cleanup -c docker --yes` executes without prompting `click.confirm`.
- [x] AC-02: `fixos dns --fix` in non-TTY without `--yes` fails fast without blocking, and `apply_dns_repair(..., non_interactive=True)` uses `sudo -n`.
- [x] AC-03: Unit tests in `tests/unit/test_cleanup_cmd.py`, `tests/unit/test_dns.py`, and `tests/unit/test_dns_plugin.py` pass alongside `./project/governance-check.sh`.
82 changes: 82 additions & 0 deletions project/ticket-186/intent.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
{
"schema": "new-project.intent/v3",
"ticket": "ticket-186",
"summary": "Fix non-interactive --yes handling in cleanup_cmd and dns_cmd/dns plugin",
"workstream": "application",
"classification": {
"kind": "BUG",
"priority": "P1",
"origin": "regression"
},
"allowedPaths": [
"project/ticket-186/**",
"TODO.md",
"project/TICKETS.md",
"fixos/cli/cleanup_cmd.py",
"fixos/cli/dns_cmd.py",
"fixos/plugins/builtin/dns.py",
"tests/unit/test_cleanup_cmd.py",
"tests/unit/test_dns.py"
],
"forbiddenPaths": [
"project/ticket-*/user-*.md"
],
"stacks": [],
"dependsOn": [],
"conflictsWith": [],
"integrationTicket": null,
"delivery": {
"targetBranch": "main",
"acceptedBaseSha": "510fb86517ba9fd39020268249a72613b34c99cd",
"outcome": "Prevent non-interactive hangs in fixos cleanup -c docker --yes and fixos dns --fix when executed by fixos auto or systemd.",
"complexity": "S",
"estimatedMinutes": 20,
"budgets": {
"maxImplementationFiles": 5,
"maxAffectedComponents": 2,
"maxPublicInterfaceChanges": 1,
"maxRuntimeDependencies": 0
},
"runtimeDependencies": [],
"nonGoals": [
"Changing fixos/cli/fix_cmd.py or altering interactive prompts when running on a TTY without --yes."
],
"architecture": {
"status": "accepted",
"decision": "Forward req.yes to _cleanup_single_service in cleanup_cmd.py, guard click.confirm on sys.stdin.isatty() in dns_cmd.py, and inject sudo -n in apply_dns_repair when non_interactive is true.",
"components": [
{
"name": "non-interactive cleanup and dns execution",
"paths": [
"fixos/cli/cleanup_cmd.py",
"fixos/cli/dns_cmd.py",
"fixos/plugins/builtin/dns.py",
"tests/unit/test_cleanup_cmd.py",
"tests/unit/test_dns.py"
]
}
],
"responsibilityChanges": false,
"interfaceChanges": [
"Add optional yes=False to _cleanup_single_service and non_interactive=None to apply_dns_repair"
],
"dataChanges": [],
"ui": {
"impact": "none",
"states": [],
"evidence": []
},
"rollback": "Revert the commit touching cleanup_cmd.py, dns_cmd.py, and dns.py."
},
"validation": [
{
"criterion": "AC-01",
"commands": [
"python -m pytest -q tests/unit/test_cleanup_cmd.py tests/unit/test_dns.py tests/unit/test_dns_plugin.py",
"./project/governance-check.sh"
],
"evidence": "All cleanup_cmd and DNS unit tests pass and governance-check passes."
}
]
}
}
28 changes: 28 additions & 0 deletions tests/unit/test_cleanup_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -799,6 +799,34 @@ def cleanup(self, **kwargs):
assert "brak zmian w Dockerze i procesach" in result.output


def test_single_service_cleanup_respects_yes_for_dangerous_service(monkeypatch):
cleaned = []

class FakeScanner:
def cleanup_service(self, service_name, *, dry_run=False, planned_service=None):
cleaned.append((service_name, dry_run))
return {"success": True, "space_freed_gb": 0.0, "output": "ok"}

monkeypatch.setattr(
cleanup_cmd,
"_single_service_target",
lambda _name, _scanner: {
"name": "Docker",
"can_cleanup": True,
"risk_level": "dangerous",
"cleanup_command": "docker builder prune --force --filter until=168h",
},
)
monkeypatch.setattr(
cleanup_cmd.click,
"confirm",
lambda *_a, **_k: (_ for _ in ()).throw(AssertionError("must not prompt when yes=True")),
)

cleanup_cmd._cleanup_single_service("docker", FakeScanner(), json_output=False, dry_run=False, yes=True)
assert cleaned == [("docker", False)]


def test_orphaned_projects_applies_only_exact_selected_identities(monkeypatch):
captured = {}

Expand Down
Loading
Loading