Skip to content

Commit de490ca

Browse files
committed
fix: avoid audit progress deadlock and honour --no-color in scope output
Share the transient line lock with the native progress projector so a reporter holding it can claim a resource terminal while another worker projects events. Pass the global --no-color flag through to scope text rendering, and describe the hollow marker as not used by this resource.
1 parent 4aa2e9b commit de490ca

14 files changed

Lines changed: 99 additions & 12 deletions

File tree

‎src/sqlbuild/.agents/skills/sqlbuild/references/docs/cli/scope.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ Available (1 of 3, 2 collapsed)
180180
└─ ● macro:formatted_order_total models/commerce/macros/orders.py:5
181181
… 2 globals collapsed; run sqb scope model:orders --globals all
182182

183-
● used by this resource ○ available but unused --verbose for scope details
183+
● used by this resource ○ not used by this resource --verbose for scope details
184184

185185
Completeness: complete
186186
```

‎src/sqlbuild/.agents/skills/sqlbuild/references/docs/concepts/declaration-scopes/explorer.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ Available (3 of 5, 2 collapsed)
8989
└─ ● macro:formatted_order_total models/commerce/macros/orders.py:4
9090
… 2 globals collapsed; run sqb scope model:orders --globals all
9191

92-
● used by this resource ○ available but unused --verbose for scope details
92+
● used by this resource ○ not used by this resource --verbose for scope details
9393

9494
Completeness: complete
9595
```
@@ -168,7 +168,7 @@ Explanation
168168
Required path: models/commerce
169169
Promotion impact: model:orders
170170

171-
● used by this resource ○ available but unused --verbose for scope details
171+
● used by this resource ○ not used by this resource --verbose for scope details
172172

173173
Diagnostics (1)
174174
ERROR S008 models/commerce/macros/orders.py: Declaration 'macro:formatted_order_total' is currently descendant-public at 'models/commerce' (models/commerce/macros/orders.py); required exact-owner-private at 'models/commerce'. Consumers: model:orders. Move it to 'models/commerce/_sqlbuild/_macros/'
@@ -292,7 +292,7 @@ Available (3 of 5, 2 collapsed)
292292
└─ ○ macro:formatted_order_total models/commerce/macros/orders.py:4
293293
… 2 globals collapsed; run sqb scope --at models/commerce/returns/new_return.sql --globals all
294294

295-
● used by this resource ○ available but unused --verbose for scope details
295+
● used by this resource ○ not used by this resource --verbose for scope details
296296

297297
Diagnostics (1)
298298
ERROR S013 models/commerce/returns/new_return.sql: Runtime usage and relationship facts are unavailable for a prospective path

‎src/sqlbuild/cli/commands/_helpers/entry/dispatch.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ def dispatch_cli_command(*, args: CliNamespace, handlers: CliEntrypointHandlers)
9090
json_output=args.json,
9191
no_cache=args.no_cache,
9292
verbose=args.verbose,
93+
no_color=args.no_color,
9394
)
9495
)
9596

‎src/sqlbuild/cli/commands/_helpers/scope/command.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def run_scope_command(
111111
else render_scope_result(
112112
result=result,
113113
request=request,
114-
use_color=output_stream is None and supports_color(),
114+
use_color=output_stream is None and not request.no_color and supports_color(),
115115
)
116116
)
117117
stream.write(output)

‎src/sqlbuild/cli/commands/_helpers/scope/output.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
_USED_MARKER: str = "●"
3535
_UNUSED_MARKER: str = "○"
3636
_LEGEND_MARKERS: str = (
37-
f"{_USED_MARKER} used by this resource {_UNUSED_MARKER} available but unused"
37+
f"{_USED_MARKER} used by this resource {_UNUSED_MARKER} not used by this resource"
3838
)
3939
_LEGEND_VERBOSE_HINT: str = "--verbose for scope details"
4040

‎src/sqlbuild/cli/commands/models.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1231,6 +1231,7 @@ class ScopeCommandRequest:
12311231
json_output: bool = False
12321232
no_cache: bool = False
12331233
verbose: bool = False
1234+
no_color: bool = False
12341235

12351236

12361237
@dataclass(frozen=True)

‎src/sqlbuild/cli/progress/classes/native_progress_projector.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def __init__(self, *, stream: TextIO, use_color: bool) -> None:
9393
self._lines: TransientLineCoordinator = shared_transient_line_coordinator()
9494
self._style: CliStyle = CliStyle(use_color=use_color)
9595
self._is_tty: bool = hasattr(stream, "isatty") and stream.isatty()
96-
self._lock: threading.RLock = threading.RLock()
96+
self._lock: threading.RLock = self._lines.lock
9797
self._seen_event_ids: set[str] = set()
9898
self._resource_ordinals: dict[str, int] = {}
9999
self._resource_total: int = 0

‎tests/unit/src/sqlbuild/cli/commands/_helpers/scope/test_output.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
"--as-path models/marts/orders.sql --globals all\n",
4343
" Lost (1)\n └─ ● enum:order_status models/staging/enums/order_status.sql:1\n",
4444
" Invalidated usages (1)\n - enum:order_status\n",
45-
"● used by this resource ○ available but unused --verbose for scope details\n",
45+
"● used by this resource ○ not used by this resource --verbose for scope details\n",
4646
"Completeness: complete\n",
4747
),
4848
unexpected_fragments=(

‎tests/unit/src/sqlbuild/cli/commands/main/entry/test_scope.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ def record(request: ScopeCommandRequest) -> int:
3535

3636
exit_code: int = _main_with_dependencies(
3737
argv=(
38+
"--no-color",
3839
"scope",
3940
"model:orders",
4041
"--as-path",
@@ -90,6 +91,7 @@ def record(request: ScopeCommandRequest) -> int:
9091
json_output=True,
9192
no_cache=True,
9293
verbose=True,
94+
no_color=True,
9395
)
9496
]
9597
assert ScopeCommandRequest.__dataclass_params__.frozen is True

‎tests/unit/src/sqlbuild/cli/commands/main/scope/test_scope.py‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import pytest
99

1010
from sqlbuild.cli.commands._helpers.runtime import adapter_context, connection
11+
from sqlbuild.cli.commands._helpers.scope import command as scope_command
1112
from sqlbuild.cli.commands._helpers.scope.command import run_scope_command
1213
from sqlbuild.cli.commands.models import ScopeCommandRequest
1314
from sqlbuild.compiler.scopes.models import ScopeCompleteness, ScopeIndex
@@ -91,6 +92,28 @@ def test_given_verbose_flag_when_rendering_json_then_bytes_match_default_json(
9192
assert "\x1b[" not in outputs[0]
9293

9394

95+
@pytest.mark.parametrize(
96+
"test_case", (ScopeCommandCase("no color flag", 0),), ids=lambda case: case.description
97+
)
98+
def test_given_no_color_flag_when_rendering_text_to_color_terminal_then_output_is_plain(
99+
monkeypatch: pytest.MonkeyPatch,
100+
capsys: pytest.CaptureFixture[str],
101+
test_case: ScopeCommandCase,
102+
) -> None:
103+
monkeypatch.setattr(scope_command, "supports_color", lambda: True)
104+
index: ScopeIndex = report_scope_lookup().index
105+
outputs: list[str] = []
106+
for no_color in (False, True):
107+
exit_code: int = run_scope_command(
108+
request=ScopeCommandRequest(target="model:orders", no_color=no_color),
109+
load_scope_index=lambda **_kwargs: index,
110+
)
111+
assert exit_code == test_case.expected_exit_code
112+
outputs.append(capsys.readouterr().out)
113+
assert "\x1b[" in outputs[0]
114+
assert "\x1b[" not in outputs[1]
115+
116+
94117
@pytest.mark.parametrize(
95118
"test_case", (ScopeCommandCase("partial", 1),), ids=lambda case: case.description
96119
)

0 commit comments

Comments
 (0)