Skip to content

refactor(cli): update --use-latest to use db instead of local information#837

Merged
AlessandroPomponio merged 10 commits into
mainfrom
ap_812_update_use_latest
Apr 14, 2026
Merged

refactor(cli): update --use-latest to use db instead of local information#837
AlessandroPomponio merged 10 commits into
mainfrom
ap_812_update_use_latest

Conversation

@AlessandroPomponio
Copy link
Copy Markdown
Member

Summary

This pull request refactors the CLI configuration system to remove the in-memory caching of latest resource identifiers and instead query them directly from the database when needed. This change improves data consistency, eliminates the need to persist resource IDs in configuration files, and ensures commands always work with the most current data.

Resolves #812

Files Changed

📄 orchestrator/cli/commands/create.py

Removed the ado_configuration.store() call after resource creation, as the configuration no longer needs to be persisted after tracking resource IDs.

📄 orchestrator/cli/commands/describe.py

Updated to pass project_context instead of the full ado_configuration object to get_effective_resource_id(), simplifying the function's dependencies.

📄 orchestrator/cli/commands/show_details.py

Updated to pass project_context instead of the full ado_configuration object to get_effective_resource_id().

📄 orchestrator/cli/commands/show_entities.py

Updated to pass project_context instead of the full ado_configuration object to get_effective_resource_id().

📄 orchestrator/cli/commands/show_related.py

Updated to pass project_context instead of the full ado_configuration object to get_effective_resource_id().

📄 orchestrator/cli/commands/show_requests.py

Updated to pass project_context instead of the full ado_configuration object to get_effective_resource_id().

📄 orchestrator/cli/commands/show_results.py

Updated to pass project_context instead of the full ado_configuration object to get_effective_resource_id().

📄 orchestrator/cli/commands/show_summary.py

Refactored to query the database directly for the latest resource ID instead of reading from configuration. Added database query with spinner feedback for better UX.

📄 orchestrator/cli/core/config.py

Removed the latest_resource_ids field from AdoConfiguration and added a Pydantic validator to strip this deprecated field from old config files for backward compatibility. Moved the store() call to the load() method to ensure configuration is persisted after context loading.

📄 orchestrator/cli/resources/actuator_configuration/create.py

Removed code that saved the created actuator configuration identifier to the in-memory configuration cache.

📄 orchestrator/cli/resources/discovery_space/create.py

Refactored to query the database for the latest sample store identifier instead of reading from configuration. Removed code that cached created resource identifiers.

📄 orchestrator/cli/resources/operation/create.py

Removed the _save_operation_identifier() helper function and all calls to save operation identifiers to configuration. Refactored reuse_requested_latest_identifiers() to use a single batch database query instead of reading from configuration.

📄 orchestrator/cli/resources/sample_store/create.py

Removed code that saved the created sample store identifier to the in-memory configuration cache.

📄 orchestrator/cli/utils/generic/common.py

Refactored get_effective_resource_id() to accept project_context instead of ado_configuration and query the database for latest resource IDs. Improved error messages and added database query with spinner feedback.

📄 orchestrator/cli/utils/generic/wrappers.py

Updated return type annotation for get_sql_store() from SQLStore to SQLResourceStore to match actual runtime behavior.

📄 orchestrator/metastore/sql/statements.py

Added new resource_select_latest_by_kinds() function that generates SQL to fetch the most recently created resource for each specified kind using window functions (ROW_NUMBER). Supports batch queries for multiple resource kinds.

📄 orchestrator/metastore/sqlstore.py

Added new get_latest_resource_identifiers_of_kinds() method to SQLResourceStore that retrieves the identifiers of the most recently created resources for multiple kinds in a single database query, minimizing round-trips.

📄 tests/fixtures/core/space.py

Updated the random_space_resource_from_file fixture to set the created timestamp on generated space resources, ensuring proper ordering in latest resource queries.

📄 tests/metastore/test_resourcestore.py

Added comprehensive test coverage for the new get_latest_resource_identifiers_of_kinds() method, including tests for empty databases, single/multiple kinds, multiple resources of the same kind, missing kinds, and invalid input validation. Refactored SQLite version checks into a reusable requires_sqlite_3_38 marker.

Signed-off-by: Alessandro Pomponio <alessandro.pomponio1@ibm.com>
Signed-off-by: Alessandro Pomponio <alessandro.pomponio1@ibm.com>
…nfiguration

Signed-off-by: Alessandro Pomponio <alessandro.pomponio1@ibm.com>
Signed-off-by: Alessandro Pomponio <alessandro.pomponio1@ibm.com>
Signed-off-by: Alessandro Pomponio <alessandro.pomponio1@ibm.com>
Signed-off-by: Alessandro Pomponio <alessandro.pomponio1@ibm.com>
Signed-off-by: Alessandro Pomponio <alessandro.pomponio1@ibm.com>
Signed-off-by: Alessandro Pomponio <alessandro.pomponio1@ibm.com>
Signed-off-by: Alessandro Pomponio <alessandro.pomponio1@ibm.com>
Copy link
Copy Markdown
Member

@michael-johnston michael-johnston left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some small changes

Comment thread .cursor/skills/resource-yaml-creation/SKILL.md Outdated
Comment thread .cursor/skills/using-ado-cli/SKILL.md Outdated
Signed-off-by: Alessandro Pomponio <alessandro.pomponio1@ibm.com>
@AlessandroPomponio AlessandroPomponio added this pull request to the merge queue Apr 14, 2026
Merged via the queue into main with commit 0e5e933 Apr 14, 2026
19 checks passed
@AlessandroPomponio AlessandroPomponio deleted the ap_812_update_use_latest branch April 14, 2026 13:16
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.

refactor(cli): make it so --use-latest references the latest identifier of the target type in the active context

2 participants