Skip to content

refactor: extract copy-paste helpers (rds, cognito, s3, bedrock, dynamodb, iam)#310

Merged
vieiralucas merged 1 commit intomainfrom
worktree-cleanup+copy-paste-helpers
Apr 12, 2026
Merged

refactor: extract copy-paste helpers (rds, cognito, s3, bedrock, dynamodb, iam)#310
vieiralucas merged 1 commit intomainfrom
worktree-cleanup+copy-paste-helpers

Conversation

@vieiralucas
Copy link
Copy Markdown
Member

@vieiralucas vieiralucas commented Apr 12, 2026

Summary

Six copy-paste sites are collapsed into named helpers. Net change: -338 lines.

Helper Sites Where What it replaces
RdsService::require_runtime 6 fakecloud-rds::service 7-line runtime.as_ref().ok_or_else(...) guard
ensure_user_pool_exists 57 fakecloud-cognito::service::* (9 files) 7-line if !state.user_pools.contains_key(...) { ... } guard
s3::xml_util::extract_tag 3 copies → 1 lifecycle.rs, inventory.rs, logging.rs byte-identical tiny XML scraper
fakecloud_bedrock::short_uuid 4 guardrails, custom_models, prompt_routers, inference_profiles Uuid::new_v4().to_string()[..8].to_string()
split_on_top_level_keyword 2 fakecloud-dynamodb::service::mod split_on_and + split_on_or had near-identical 30-line parenthesis-aware scanners; they now dispatch to a single keyword-parameterised helper
extract_xml_tag (test helper) 6 fakecloud-iam::iam_service test module body.find("<Arn>").unwrap() + 5 ... body.find("</Arn>").unwrap()

No behavior change; the extracted helpers keep byte-identical semantics to what they replace.

Test plan

  • cargo build --workspace
  • cargo fmt --check
  • cargo clippy --workspace --all-targets -- -D warnings
  • cargo test --workspace --exclude fakecloud-e2e --exclude fakecloud-conformance — 1102 passed, 0 failed
  • CI green

Summary by cubic

Collapsed repeated guards and utilities into shared helpers across fakecloud-rds, fakecloud-cognito, fakecloud-s3, fakecloud-bedrock, fakecloud-dynamodb, and fakecloud-iam to cut duplication. No behavior changes.

  • Refactors
    • RdsService::require_runtime() centralizes the Docker/Podman runtime check in fakecloud-rds.
    • ensure_user_pool_exists de-duplicates user-pool guards across fakecloud-cognito service modules.
    • s3::xml_util::extract_tag replaces three identical XML tag scrapers in lifecycle, inventory, and logging.
    • fakecloud_bedrock::short_uuid() standardizes 8-char IDs for guardrails, custom models, prompt routers, and inference profiles.
    • split_on_top_level_keyword powers both split_on_and and split_on_or in fakecloud-dynamodb.
    • IAM tests use extract_xml_tag to pull <Arn> from XML responses.

Written for commit 7c2edc2. Summary will update on new commits.

…modb, iam)

Five copy-pasted blocks are collapsed into named helpers:

- **RDS runtime check**: the six ``self.runtime.as_ref().ok_or_else(...)``
  guards in ``fakecloud-rds::service`` become one ``require_runtime``
  helper that returns the shared ``ServiceUnavailable`` error. Caller
  sites drop from seven lines to one.
- **Cognito user-pool existence**: 57 copies of the
  ``if !state.user_pools.contains_key(pool_id) { return Err(...) }``
  guard across 9 Cognito service submodules become one
  ``ensure_user_pool_exists(&state, pool_id)?;`` call. Every caller
  previously had its own chance to misspell the error string or get the
  status code wrong.
- **S3 XML tag scraper**: three byte-identical copies of
  ``extract_tag`` (in ``lifecycle.rs``, ``inventory.rs``, ``logging.rs``)
  become a single private helper in a new ``s3::xml_util`` module.
- **Bedrock short UUIDs**: four copies of
  ``Uuid::new_v4().to_string()[..8].to_string()`` become a crate-level
  ``short_uuid()`` helper, and the stray ``uuid`` imports are dropped.
- **DynamoDB filter splitters**: ``split_on_and`` and ``split_on_or``
  had the same 30-line parenthesis-aware scanner with only the
  separator length and keyword differing. Both now dispatch to
  ``split_on_top_level_keyword(expr, keyword)``.
- **IAM test ARN extraction**: six copies of
  ``body.find("<Arn>").unwrap() + 5 ... body.find("</Arn>")`` in the
  IAM test suite become ``extract_xml_tag(&body, "Arn")``.

No behavior change; 1102 unit tests still pass.
Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

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

No issues found across 23 files

@vieiralucas vieiralucas merged commit b09430d into main Apr 12, 2026
22 checks passed
@vieiralucas vieiralucas deleted the worktree-cleanup+copy-paste-helpers branch April 12, 2026 22:45
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.

1 participant