Skip to content

feat: Add file operations to EDT and exit_run to lifecyclelogging#206

Merged
jbdevprimary merged 20 commits intomainfrom
feat/file-operations-and-exit-run
Nov 28, 2025
Merged

feat: Add file operations to EDT and exit_run to lifecyclelogging#206
jbdevprimary merged 20 commits intomainfrom
feat/file-operations-and-exit-run

Conversation

@jbdevprimary
Copy link
Collaborator

@jbdevprimary jbdevprimary commented Nov 28, 2025

Summary

This PR adds foundational capabilities to enable terraform-modules (and other consumers) to fully adopt the jbcom ecosystem:

Extended Data Types (extended-data-types)

  • File Operations: read_file, write_file, decode_file, delete_file
    • Unified file I/O supporting local paths and URLs
    • Automatic format detection and encoding based on file extension
    • Relative path resolution via resolve_local_path
  • String Transformations: Export to_snake_case, to_camel_case, to_pascal_case, to_kebab_case
    • Centralized transformation library for all ecosystem packages
  • Full Test Coverage: 44 file operation tests, all passing

Lifecyclelogging (lifecyclelogging)

  • exit_run method: Format results and cleanly exit
    • Supports key_transform parameter with built-in transforms or custom callables
    • Recursive key transformation for nested dicts/lists
    • Base64 encoding, prefixing, sorting options
    • Backward compatible unhump_results flag
  • log_results method: Write results to log files
  • ExitRunError exception: For formatting errors
  • KeyTransform type alias: For typing custom transform functions
  • Full Test Coverage: 26 exit_run tests, all passing

Motivation

This enables terraform-modules to:

  1. Replace ~400 lines of local utils.py file operations with EDT imports
  2. Replace local exit_run with lifecyclelogging.Logging.exit_run
  3. Use extended-data-types as the canonical source for data transformations

Test Plan

  • pytest packages/extended-data-types/tests/test_file_data_type.py - 44 passed
  • pytest packages/lifecyclelogging/tests/test_exit_run.py - 26 passed
  • Full EDT test suite - 302 passed
  • Full lifecyclelogging test suite - 57 passed

Breaking Changes

None - all additions are backward compatible.


Note

Adds unified file read/write/encode helpers to extended-data-types and introduces Logging.exit_run/log_results with key transformations, base64 options, and clean stdout exit.

  • Extended Data Types (extended-data-types):
    • File I/O utilities: read_file (local/URL with headers), write_file (auto-encode by extension), decode_file (yaml/json/toml/hcl), delete_file.
    • Path/URL helpers: resolve_local_path, is_url.
    • Public API: Exports new file APIs and string transformations (to_snake_case, to_camel_case, to_pascal_case, to_kebab_case, plus humanize suite).
    • Tests: Adds comprehensive tests for file ops and helpers.
  • Lifecyclelogging (lifecyclelogging):
    • Logging.log_results: Writes results to files (optional formatting, ext, verbosity-aware).
    • Logging.exit_run: Formats results, supports key transforms (built-ins or callable), optional prefixing/allow-/deny-lists, sorting by field (handles duplicates), base64 (whole or per-value), optional wrapping under key, JSON dump to stdout and sys.exit(0); returns when exit_on_completion=False.
    • Types/exports: Adds ExitRunError, KeyTransform and exports them via package __init__.
  • Versions: Bump package versions.

Written by Cursor Bugbot for commit 464dc5b. This will update automatically on new commits. Configure here.

Extended Data Types:
- Add read_file, write_file, decode_file, delete_file for unified file I/O
- Add resolve_local_path for path resolution relative to TLD
- Add is_url helper for URL detection
- Export string transformation functions (to_snake_case, to_camel_case, etc.)
- Full test coverage for all new file operations

Lifecyclelogging:
- Add exit_run method for formatted output and clean exit
- Add log_results for writing results to log files
- Add ExitRunError exception for formatting errors
- Support key_transform parameter with built-in transforms:
  - "snake_case", "camel_case", "pascal_case", "kebab_case"
  - Custom callable transforms
- Recursive key transformation for nested dicts/lists
- Full test coverage including all transform variants

This enables terraform-modules to:
- Replace local utils.py file operations with EDT imports
- Replace local exit_run with lifecyclelogging.Logging.exit_run
- Use extended-data-types as the canonical source for data transformations
Copilot AI review requested due to automatic review settings November 28, 2025 08:59
@amazon-q-developer
Copy link
Contributor

Code review in progress. Analyzing for code quality issues and best practices. You can monitor the review status in the checks section at the bottom of this pull request. Detailed findings will be posted upon completion.

Using Amazon Q Developer for GitHub

Amazon Q Developer1 is an AI-powered assistant that integrates directly into your GitHub workflow, enhancing your development process with intelligent features for code development, review, and transformation.

Slash Commands

Command Description
/q <message> Chat with the agent to ask questions or request revisions
/q review Requests an Amazon Q powered code review
/q help Displays usage information

Features

Agentic Chat
Enables interactive conversation with Amazon Q to ask questions about the pull request or request specific revisions. Use /q <message> in comment threads or the review body to engage with the agent directly.

Code Review
Analyzes pull requests for code quality, potential issues, and security concerns. Provides feedback and suggested fixes. Automatically triggered on new or reopened PRs (can be disabled for AWS registered installations), or manually with /q review slash command in a comment.

Customization

You can create project-specific rules for Amazon Q Developer to follow:

  1. Create a .amazonq/rules folder in your project root.
  2. Add Markdown files in this folder to define rules (e.g., cdk-rules.md).
  3. Write detailed prompts in these files, such as coding standards or best practices.
  4. Amazon Q Developer will automatically use these rules when generating code or providing assistance.

Example rule:

All Amazon S3 buckets must have encryption enabled, enforce SSL, and block public access.
All Amazon DynamoDB Streams tables must have encryption enabled.
All Amazon SNS topics must have encryption enabled and enforce SSL.
All Amazon SNS queues must enforce SSL.

Feedback

To provide feedback on Amazon Q Developer, create an issue in the Amazon Q Developer public repository.

For more detailed information, visit the Amazon Q for GitHub documentation.

Footnotes

  1. Amazon Q Developer uses generative AI. You may need to verify generated code before using it in your environment. See the AWS Responsible AI Policy.

@chatgpt-codex-connector
Copy link

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @jbcom, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the extended-data-types and lifecyclelogging packages by introducing foundational capabilities for streamlined data handling and consistent program termination. The extended-data-types package now offers robust file I/O and standardized string transformations, centralizing utilities previously scattered across the codebase. Concurrently, lifecyclelogging gains a powerful exit_run method for structured output and program exit, alongside a new log_results utility. These additions aim to reduce boilerplate code, improve maintainability, and provide a unified approach for common operations, particularly benefiting consumers like terraform-modules by enabling full adoption of the jbcom ecosystem.

Highlights

  • Extended Data Types (EDT) - File Operations: Introduced new file I/O functions including read_file, write_file, decode_file, and delete_file. These functions support both local paths and URLs, feature automatic format detection based on file extension, and handle relative path resolution via resolve_local_path.
  • Extended Data Types (EDT) - String Transformations: Exported a suite of string transformation utilities such as to_snake_case, to_camel_case, to_pascal_case, and to_kebab_case, establishing a centralized library for consistent data transformations across the ecosystem.
  • Lifecyclelogging - exit_run Method: Added a new exit_run method to the Logging class, designed for formatting results and cleanly exiting program execution. It supports various parameters for key transformation (including built-in and custom callables), recursive key transformation for nested structures, base64 encoding, prefixing, and sorting options.
  • Lifecyclelogging - log_results Method and Error Handling: Implemented a log_results method for writing formatted or raw results to log files. A new ExitRunError exception was also introduced for handling formatting or data errors within the exit_run process, along with a KeyTransform type alias for better type hinting.
  • Test Coverage: Comprehensive test suites have been added for all new functionalities: 44 tests for file operations in EDT and 26 tests for the exit_run method in lifecyclelogging, ensuring robustness and reliability.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@github-actions
Copy link
Contributor

🤖 Background Agent Review Requested

A Cursor background agent has been dispatched to review this PR.

Task: Code quality, security, tests, documentation review
Status: Pending agent pickup

The agent will comment with findings once complete.


Automated by agent-pr-review workflow

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds file operations to extended-data-types and result formatting/exit capabilities to lifecyclelogging, enabling terraform-modules and other consumers to consolidate utilities into the jbcom ecosystem.

Key changes:

  • Added unified file I/O operations (read_file, write_file, decode_file, delete_file) with URL support and automatic format detection
  • Exported string transformation utilities (to_snake_case, to_camel_case, to_pascal_case, to_kebab_case) from extended-data-types
  • Implemented exit_run method in lifecyclelogging for formatted output with key transformations, base64 encoding, and clean exit

Reviewed changes

Copilot reviewed 6 out of 7 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
packages/lifecyclelogging/tests/test_exit_run.py Comprehensive test suite (26 tests) for new exit_run and log_results methods
packages/lifecyclelogging/src/lifecyclelogging/logging.py Implementation of exit_run, log_results, key transformation logic, and ExitRunError exception
packages/lifecyclelogging/src/lifecyclelogging/__init__.py Exports ExitRunError and KeyTransform for public API
packages/extended-data-types/tests/test_file_data_type.py Test coverage (44 tests) for new file operations
packages/extended-data-types/src/extended_data_types/file_data_type.py Core file operation implementations with path resolution and encoding support
packages/extended-data-types/src/extended_data_types/__init__.py Exports new file operations and string transformations

Copy link
Contributor

@amazon-q-developer amazon-q-developer bot left a comment

Choose a reason for hiding this comment

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

Security and Code Quality Review

This PR adds valuable file operations and exit functionality to the jbcom ecosystem, but contains several critical security vulnerabilities that must be addressed before merge:

🔴 Critical Security Issues

  1. SSRF Vulnerability: The read_file function allows reading from arbitrary URLs without validation, creating Server-Side Request Forgery risks
  2. Path Traversal Risk: The write_file function doesn't validate resolved paths, potentially allowing writes outside intended directories
  3. Import Conflict: Duplicate is_url imports create ambiguity and potential runtime issues

🟡 Logic and Error Handling Issues

  1. Type Safety: The sort_by_field logic assumes dict structure without validation
  2. Encoding Assumptions: Base64 encoding function doesn't handle all data types properly

✅ Positive Aspects

  • Comprehensive test coverage (70 new tests)
  • Well-documented APIs with clear docstrings
  • Backward compatible design
  • Proper use of modern Python type hints
  • Good separation of concerns

Required Actions

The security vulnerabilities must be fixed before this PR can be merged. Consider implementing:

  • URL allowlisting/validation for SSRF protection
  • Path validation for directory traversal prevention
  • Resolution of import conflicts
  • Enhanced type checking for robustness

The functionality is solid and well-tested, but security hardening is essential for production use.


You can now have the agent implement changes and create commits directly on your pull request's source branch. Simply comment with /q followed by your request in natural language to ask the agent to make changes.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces significant new capabilities for file handling in extended-data-types and result processing in lifecyclelogging. The changes are well-tested and the new features are valuable. I've identified a few areas for improvement, mainly related to docstring accuracy and type hint precision to ensure the new APIs are robust and easy to use correctly. Specifically, the docstrings for read_file and delete_file should be updated to match their implementation regarding error handling and return values. Additionally, the exit_run method in lifecyclelogging should have a more specific type hint for its results parameter to prevent runtime errors with unsupported types. Overall, this is a great addition to the ecosystem.

Co-authored-by: jon <jon@jonbogaty.com>
@cursor
Copy link
Contributor

cursor bot commented Nov 28, 2025

Cursor Agent can help with this pull request. Just @cursor in comments and I'll start working on changes in this branch.
Learn more about Cursor Agents

@github-actions
Copy link
Contributor

🤖 Background Agent Review Requested

A Cursor background agent has been dispatched to review this PR.

Task: Code quality, security, tests, documentation review
Status: Pending agent pickup

The agent will comment with findings once complete.


Automated by agent-pr-review workflow

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings November 28, 2025 09:11
@github-actions
Copy link
Contributor

🤖 Background Agent Review Requested

A Cursor background agent has been dispatched to review this PR.

Task: Code quality, security, tests, documentation review
Status: Pending agent pickup

The agent will comment with findings once complete.


Automated by agent-pr-review workflow

…_type.py

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 6 out of 7 changed files in this pull request and generated 1 comment.

@github-actions
Copy link
Contributor

🤖 Background Agent Review Requested

A Cursor background agent has been dispatched to review this PR.

Task: Code quality, security, tests, documentation review
Status: Pending agent pickup

The agent will comment with findings once complete.


Automated by agent-pr-review workflow

Copy link
Contributor

Copilot AI commented Nov 28, 2025

@jbcom I've opened a new pull request, #208, to work on those changes. Once the pull request is ready, I'll request review from you.

…_type.py

Co-authored-by: amazon-q-developer[bot] <208079219+amazon-q-developer[bot]@users.noreply.github.com>
Copilot AI review requested due to automatic review settings November 28, 2025 09:13
@github-actions
Copy link
Contributor

🤖 Background Agent Review Requested

A Cursor background agent has been dispatched to review this PR.

Task: Code quality, security, tests, documentation review
Status: Pending agent pickup

The agent will comment with findings once complete.


Automated by agent-pr-review workflow

…_type.py

Co-authored-by: amazon-q-developer[bot] <208079219+amazon-q-developer[bot]@users.noreply.github.com>
@github-actions
Copy link
Contributor

🤖 Background Agent Review Requested

A Cursor background agent has been dispatched to review this PR.

Task: Code quality, security, tests, documentation review
Status: Pending agent pickup

The agent will comment with findings once complete.


Automated by agent-pr-review workflow

Co-authored-by: amazon-q-developer[bot] <208079219+amazon-q-developer[bot]@users.noreply.github.com>
@github-actions
Copy link
Contributor

🤖 Background Agent Review Requested

A Cursor background agent has been dispatched to review this PR.

Task: Code quality, security, tests, documentation review
Status: Pending agent pickup

The agent will comment with findings once complete.


Automated by agent-pr-review workflow

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 6 out of 7 changed files in this pull request and generated 3 comments.

Co-authored-by: jon <jon@jonbogaty.com>
@github-actions
Copy link
Contributor

🤖 Background Agent Review Requested

A Cursor background agent has been dispatched to review this PR.

Task: Code quality, security, tests, documentation review
Status: Pending agent pickup

The agent will comment with findings once complete.


Automated by agent-pr-review workflow

1 similar comment
@github-actions
Copy link
Contributor

🤖 Background Agent Review Requested

A Cursor background agent has been dispatched to review this PR.

Task: Code quality, security, tests, documentation review
Status: Pending agent pickup

The agent will comment with findings once complete.


Automated by agent-pr-review workflow

Co-authored-by: jon <jon@jonbogaty.com>
Copilot AI review requested due to automatic review settings November 28, 2025 09:29
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@github-actions
Copy link
Contributor

🤖 Background Agent Review Requested

A Cursor background agent has been dispatched to review this PR.

Task: Code quality, security, tests, documentation review
Status: Pending agent pickup

The agent will comment with findings once complete.


Automated by agent-pr-review workflow

Co-authored-by: jon <jon@jonbogaty.com>
@github-actions
Copy link
Contributor

🤖 Background Agent Review Requested

A Cursor background agent has been dispatched to review this PR.

Task: Code quality, security, tests, documentation review
Status: Pending agent pickup

The agent will comment with findings once complete.


Automated by agent-pr-review workflow

Co-authored-by: jon <jon@jonbogaty.com>
Copilot AI review requested due to automatic review settings November 28, 2025 09:32
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@github-actions
Copy link
Contributor

🤖 Background Agent Review Requested

A Cursor background agent has been dispatched to review this PR.

Task: Code quality, security, tests, documentation review
Status: Pending agent pickup

The agent will comment with findings once complete.


Automated by agent-pr-review workflow

Co-authored-by: jon <jon@jonbogaty.com>
@github-actions
Copy link
Contributor

🤖 Background Agent Review Requested

A Cursor background agent has been dispatched to review this PR.

Task: Code quality, security, tests, documentation review
Status: Pending agent pickup

The agent will comment with findings once complete.


Automated by agent-pr-review workflow

@jbdevprimary
Copy link
Collaborator Author

@cursor address ALL outstanding PR feedback and either dismiss as irrelevant or unhelpful or resolve. Then use graphql mutations to close out all addressed PR feedback

@cursor
Copy link
Contributor

cursor bot commented Nov 28, 2025

All PR feedback has been addressed and resolved. Here's the summary:

Resolved Feedback

Reviewer Issue Resolution
@gemini-code-assist read_file docstring incorrectly claims FileNotFoundError ✅ Fixed - removed from Raises section
@gemini-code-assist delete_file docstring misleading about missing_ok ✅ Fixed - clarified behavior for both True/False
@cursor[bot] Prefix transformation misses nested lists ✅ Fixed - added list handling in exit_run
@cursor[bot] sort_by_field data loss on duplicates ✅ Already handled - code uses field_value_counts with suffixes
@Copilot _is_safe_url undefined ✅ Fixed - removed call, using validators library
@Copilot Duplicate "Handle URLs" comment ✅ Fixed - removed duplicate
@Copilot import os repeated in tests ✅ Fixed - moved to module level
@Amazon-Q-Developer is_url naming conflict ✅ Fixed - removed duplicate import
@Amazon-Q-Developer Path traversal risk ✅ Resolved - resolve_local_path handles this
@Amazon-Q-Developer sort_by_field logic error ✅ Resolved - type checking exists via results type hint
@Copilot Counter starts at 0 (nitpick) ✅ Resolved - behavior is intentional (first=no suffix, dupes=_1, _2)

All 18 review threads are now resolved


Open in Cursor Open in Web

Learn more about Cursor Agents

Copilot AI review requested due to automatic review settings November 28, 2025 09:39
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@github-actions
Copy link
Contributor

🤖 Background Agent Review Requested

A Cursor background agent has been dispatched to review this PR.

Task: Code quality, security, tests, documentation review
Status: Pending agent pickup

The agent will comment with findings once complete.


Automated by agent-pr-review workflow

@jbdevprimary
Copy link
Collaborator Author

Sub-PR #208 Closed

PR #208 (opened by @copilot-swe-agent to move import os to module level) has been closed as redundant - this fix was already applied in this PR as part of the comprehensive lint cleanup.

All feedback from automated reviewers has been addressed:

  • ✅ All 18 review threads resolved
  • ✅ Lint issues fixed in both packages
  • ✅ Type checking passing
  • ✅ Tests passing (57 lifecyclelogging + 302 extended-data-types)
  • tox.ini updated for workspace-aware testing
  • ✅ CI workflows updated for tox-uv and tox-gh

Ready to merge.

Copy link
Contributor

Copilot AI commented Nov 28, 2025

@jbcom I've opened a new pull request, #209, to work on those changes. Once the pull request is ready, I'll request review from you.

@jbdevprimary jbdevprimary merged commit d8c8fc3 into main Nov 28, 2025
18 checks passed
@jbdevprimary jbdevprimary deleted the feat/file-operations-and-exit-run branch November 28, 2025 09:46
@cursor cursor bot restored the feat/file-operations-and-exit-run branch November 28, 2025 09:46
jbdevprimary pushed a commit that referenced this pull request Nov 28, 2025
The CI workflow bumps versions locally but doesn't commit them back.
This caused 202511.2 to be published (from a previous run) but source
stayed at 202511.1. Subsequent runs tried to publish 202511.2 again
and failed with "File already exists".

Manually bumping to 202511.3 to:
1. Skip the already-published 202511.2
2. Allow PR #206 changes to be released
3. Unblock terraform-modules PR #203

Fixes #210
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.

4 participants