fix(resource): trigger auto-discovery when adding resource #6745

Merged
HAL9000 merged 8 commits from fix/issue-6464-resource-add-auto-discovery into master 2026-06-06 09:50:06 +00:00

8 Commits

Author SHA1 Message Date
HAL9000 ba8c424897 test(resource-cli): cover auto-discovered children rich output path
CI / lint (pull_request) Successful in 1m3s
CI / typecheck (pull_request) Successful in 1m24s
CI / quality (pull_request) Successful in 1m28s
CI / helm (pull_request) Successful in 1m10s
CI / build (pull_request) Successful in 1m16s
CI / security (pull_request) Successful in 1m42s
CI / push-validation (pull_request) Successful in 25s
CI / unit_tests (pull_request) Successful in 5m56s
CI / docker (pull_request) Successful in 1m41s
CI / integration_tests (pull_request) Successful in 16m43s
CI / coverage (pull_request) Successful in 12m47s
CI / status-check (pull_request) Successful in 3s
CI / lint (push) Successful in 40s
CI / helm (push) Successful in 1m2s
CI / typecheck (push) Successful in 1m10s
CI / quality (push) Successful in 1m18s
CI / build (push) Successful in 1m21s
CI / security (push) Successful in 2m20s
CI / push-validation (push) Successful in 26s
CI / e2e_tests (push) Successful in 57s
CI / unit_tests (push) Successful in 10m14s
CI / docker (push) Successful in 2m47s
CI / integration_tests (push) Successful in 16m51s
CI / coverage (push) Successful in 12m57s
CI / status-check (push) Successful in 4s
CI / benchmark-regression (push) Has started running
CI / benchmark-publish (push) Has been cancelled
Add a Behave scenario that adds an fs-directory resource at a seeded
directory via the CLI. This exercises the if-children branch in
resource_add (lines 857-887 of resource.py), including _short_resource_id,
_format_child_status, and the Rich child table rendering — all previously
uncovered because no existing scenario produced auto-discovered children
through the resource add command path.

ISSUES CLOSED: #6464
2026-06-06 05:30:16 -04:00
HAL9000 bbf1915d54 fix(resource): preserve atomicity in register_resource without breaking shared-session callers
The previous attempt wrapped `register_resource` in `with session.begin():`
to guarantee parent + auto-discovered children commit atomically.  That
pattern raises `sqlalchemy.exc.InvalidRequestError: A transaction is
already begun on this Session.` whenever a caller (e.g. the WF05
integration helper at `robot/helper_int_wf05_db_migration.py`) reuses a
single Session across multiple service calls — autobegin has already
opened the implicit transaction by the time `register_resource` runs.

This rewrites the flow to keep the simpler `session.commit()` pattern
that worked with shared sessions, but moves the commit to AFTER
`auto_discover_children` so any failure between `session.add(parent)`
and `session.commit()` rolls the whole transaction back via the
existing `except`/`session.rollback()` handlers.  Atomicity is
preserved (parent is never persisted on an auto-discovery failure) and
shared-session callers no longer get the `InvalidRequestError`.

Also stabilises the `Service get_children returns auto-discovered
children for directory` scenario in `features/resource_cli_tree.feature`
by adding an explicit `Given a seeded directory exists at "/tmp/gcl"`
step that creates the directory and writes a sentinel file.  Without
this seed the scenario depended on whatever happened to exist at
`/tmp/gcl` in the CI environment.

ISSUES CLOSED: #6464
2026-06-06 05:30:16 -04:00
HAL9000 7bcc212de5 fix(resource): address reviewer feedback on auto-discovery atomicity
- Always rollback session unconditionally in auto_discover_children
  except blocks (both ResourceNotFoundRepoError and OperationalError/
  SQLAlchemyDatabaseError), regardless of commit/own_session flags.
  This ensures @database_retry retries with a clean session and callers
  continue to see the original DatabaseError instead of
  sqlalchemy.exc.PendingRollbackError.
- Remove unused 'auto_exc' binding in register_resource's auto-discovery
  exception handler (use bare 'except Exception:' instead).
- Move all 'from datetime import UTC, datetime' imports from inside
  function bodies to module-level in
  resource_registry_service_coverage_steps.py.

ISSUES CLOSED: #6464
2026-06-06 05:30:16 -04:00
HAL9000 682902a11c fix(resource): ensure resource add remains atomic when discovery fails 2026-06-06 05:30:16 -04:00
HAL9000 5c9002c540 test(resource-cli): expect auto-discovered children
Update resource CLI tree Behave scenario to expect auto-discovery output and add a reusable assertion for minimum child counts. Refs: #6464
2026-06-06 05:30:16 -04:00
HAL9000 5df4d2c4bc fix(resource-registry): keep resource auto discovery atomic 2026-06-06 05:30:16 -04:00
HAL9000 58cb75e5b8 fix(resource): keep register resource atomic
Ensure the resource registry removes the parent record when auto-discovery raises so the operation remains atomic.

Refs: #6464
2026-06-06 05:30:16 -04:00
HAL9000 bc0baae777 fix(resource): trigger auto-discovery when adding resource (#6464)
ISSUES CLOSED: #6464
2026-06-06 05:30:16 -04:00