Skip to content

🧪 [testing improvement] Add tests for decryptor parser and sanitizer#229

Open
Ven0m0 wants to merge 1 commit intomainfrom
test-decryptor-parser-10260828444860348659
Open

🧪 [testing improvement] Add tests for decryptor parser and sanitizer#229
Ven0m0 wants to merge 1 commit intomainfrom
test-decryptor-parser-10260828444860348659

Conversation

@Ven0m0
Copy link
Owner

@Ven0m0 Ven0m0 commented Mar 16, 2026

This PR addresses the testing gap for the parse_ctrtool_output function in cia_3ds_decryptor.py.

🎯 What:

  • Added a new test suite Cachyos/Scripts/WIP/emu/test_decryptor_parser.py.
  • Fixed a bug in cia_3ds_decryptor.py where title_version was not being updated correctly during parsing.

📊 Coverage:

  • parse_ctrtool_output: Full, partial, and empty output scenarios.
  • parse_twl_ctrtool_output: TWL-specific output parsing.
  • sanitize_filename: Filename sanitization with various character sets and case preservation.

Result:

  • Increased test coverage and reliability for the decryption script.
  • Improved accuracy of title version parsing.

PR created automatically by Jules for task 10260828444860348659 started by @Ven0m0

Introduces comprehensive unit tests for `parse_ctrtool_output`,
`parse_twl_ctrtool_output`, and `sanitize_filename` in
`cia_3ds_decryptor.py`.

Fixes a bug in the parser logic where `title_version` would not be
updated if it was already initialized to its default value '0'.
The updated logic ensures that any version information found in
the tool output is correctly captured.

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
@google-labs-jules
Copy link
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

Copilot AI review requested due to automatic review settings March 16, 2026 22:21
@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, 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 introduces a new, dedicated test suite to improve the reliability and robustness of the 3DS decryption script's parsing and sanitization functionalities. It addresses a critical bug in the cia_3ds_decryptor.py module, ensuring that title version information is accurately extracted. These changes collectively enhance the script's ability to correctly process and interpret ctrtool output, leading to more dependable decryption operations.

Highlights

  • New Test Suite: Added a new test suite, Cachyos/Scripts/WIP/emu/test_decryptor_parser.py, to enhance testing for the cia_3ds_decryptor.py module.
  • Bug Fix: Fixed a bug in cia_3ds_decryptor.py where the title_version was not consistently updated during the parsing of ctrtool output.
  • Increased Test Coverage: Significantly increased test coverage for parse_ctrtool_output, parse_twl_ctrtool_output, and sanitize_filename functions, covering various input scenarios.
Changelog
  • Cachyos/Scripts/WIP/emu/cia_3ds_decryptor.py
    • Modified the parse_ctrtool_output and parse_twl_ctrtool_output functions to ensure title_version is always updated if found, removing a condition that prevented re-assignment.
  • Cachyos/Scripts/WIP/emu/test_decryptor_parser.py
    • Created a new Python unit test file.
    • Implemented test_parse_ctrtool_output_full, test_parse_ctrtool_output_partial, and test_parse_ctrtool_output_empty to validate parse_ctrtool_output.
    • Added test_parse_twl_ctrtool_output_full to verify parse_twl_ctrtool_output.
    • Included test_sanitize_filename to check filename sanitization, including case preservation and handling of invalid characters.
Activity
  • No human activity has been recorded for this pull request yet.
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.

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 adds valuable tests for the decryptor parsing logic and fixes a bug in version parsing. The changes are well-implemented. I've added a couple of suggestions to further improve the test suite's robustness and maintainability. Specifically, I recommend adding a test case that explicitly verifies the bug fix for multiple version entries and refactoring the duplicated module import logic into a shared test utility.

Comment on lines +7 to +14
# Dynamically import cia_3ds_decryptor.py
file_path = Path(__file__).parent / "cia_3ds_decryptor.py"
spec = importlib.util.spec_from_file_location("cia_3ds_decryptor", str(file_path))
if spec is None:
raise ImportError(f"Could not load {file_path}")
decryptor = importlib.util.module_from_spec(spec)
sys.modules["cia_3ds_decryptor"] = decryptor
spec.loader.exec_module(decryptor)
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

This dynamic import logic is duplicated in test_decryptor_counters.py. To improve maintainability and reduce code duplication, consider refactoring this logic into a shared test helper function. For example, you could create a test_helper.py with a function that handles the module loading, which both test files can then import and use.

# Test that it preserves case (if TRANSLATE_TABLE is correct)
self.assertEqual(decryptor.sanitize_filename("UPPERCASE.CIA"), "UPPERCASE.CIA")
# If all characters are invalid, it returns the original string
self.assertEqual(decryptor.sanitize_filename("!!!"), "!!!")
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

To ensure the bug fix for title_version parsing is robustly tested, it's a good practice to add a test case that explicitly covers the fixed behavior. The current tests don't cover the scenario where multiple TitleVersion lines are present in the input. Adding a test for this will verify that the parser correctly captures the last value, as intended by the fix.

Suggested change
self.assertEqual(decryptor.sanitize_filename("!!!"), "!!!")
self.assertEqual(decryptor.sanitize_filename("!!!"), "!!!")
def test_version_parsing_uses_last_value(self):
text_with_multiple_versions = """
Title id: 0004000000000100
TitleVersion: 1
TitleVersion: 10
Crypto Key: Secure
"""
# Test standard parser
info = decryptor.parse_ctrtool_output(text_with_multiple_versions)
self.assertEqual(info.title_version, "10")
# Test TWL parser
info_twl = decryptor.parse_twl_ctrtool_output(text_with_multiple_versions)
self.assertEqual(info_twl.title_version, "10")

@github-actions
Copy link
Contributor

Lint/Format Check Failed

Please run ./lint-format.sh locally to fix formatting issues.

@kilo-code-bot
Copy link

kilo-code-bot bot commented Mar 16, 2026

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Overview

This PR fixes a bug in cia_3ds_decryptor.py where the title_version field was never being extracted from ctrtool output.

Severity Count
CRITICAL 0
WARNING 0
SUGGESTION 0

Analysis

The original code had:

if not info.title_version and (m := TITLE_VERSION_RE.search(line)):

Since title_version defaults to "0" (a truthy string in Python), not "0" evaluates to False, preventing the version from ever being extracted. The fix removes this broken check, allowing proper version extraction.

Files Reviewed (2 files)

  • Cachyos/Scripts/WIP/emu/cia_3ds_decryptor.py - Bug fix
  • Cachyos/Scripts/WIP/emu/test_decryptor_parser.py - New tests

This is a valid bug fix with appropriate test coverage.


Reviewed by minimax-m2.5 · 316,980 tokens

@aviator-app
Copy link

aviator-app bot commented Mar 16, 2026

Current Aviator status

Aviator will automatically update this comment as the status of the PR changes.
Comment /aviator refresh to force Aviator to re-examine your PR (or learn about other /aviator commands).

This pull request is currently open (not queued).

How to merge

To merge this PR, comment /aviator merge or add the mergequeue label.


See the real-time status of this PR on the Aviator webapp.
Use the Aviator Chrome Extension to see the status of your PR within GitHub.

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

Adds unit tests covering ctrtool output parsing and filename sanitization for the 3DS CIA decryptor, and fixes a parsing bug where title_version could remain at its default value even when present in the input.

Changes:

  • Add unittest suite for parse_ctrtool_output, parse_twl_ctrtool_output, and sanitize_filename.
  • Fix title_version parsing so it updates when a TitleVersion: line is found (CTR + TWL parsers).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
Cachyos/Scripts/WIP/emu/test_decryptor_parser.py New unit tests for parser and sanitizer behavior.
Cachyos/Scripts/WIP/emu/cia_3ds_decryptor.py Fixes TitleVersion extraction by removing the incorrect “only if unset” guard.

You can also share your feedback on Copilot code review. Take the survey.

Comment on lines +17 to +61
def test_parse_ctrtool_output_full(self):
text = """
Title id: 0004000000000100
TitleVersion: 10
Crypto Key: Secure
"""
info = decryptor.parse_ctrtool_output(text)
self.assertEqual(info.title_id, "0004000000000100")
self.assertEqual(info.title_version, "10")
self.assertEqual(info.crypto_key, "Crypto Key: Secure")

def test_parse_ctrtool_output_partial(self):
text = "Title id: 0004000000000100"
info = decryptor.parse_ctrtool_output(text)
self.assertEqual(info.title_id, "0004000000000100")
self.assertEqual(info.title_version, "0")
self.assertEqual(info.crypto_key, "")

def test_parse_ctrtool_output_empty(self):
info = decryptor.parse_ctrtool_output("")
self.assertEqual(info.title_id, "")
self.assertEqual(info.title_version, "0")
self.assertEqual(info.crypto_key, "")

def test_parse_twl_ctrtool_output_full(self):
text = """
TitleId: 0004800000000100
TitleVersion: 5
Encrypted: YES
"""
info = decryptor.parse_twl_ctrtool_output(text)
self.assertEqual(info.title_id, "0004800000000100")
self.assertEqual(info.title_version, "5")
self.assertEqual(info.crypto_key, "YES")

def test_sanitize_filename(self):
self.assertEqual(decryptor.sanitize_filename("Game Name (USA)!?.cia"), "Game Name USA.cia")
self.assertEqual(decryptor.sanitize_filename("valid_name-123.3ds"), "valid_name-123.3ds")
# Test that it preserves case (if TRANSLATE_TABLE is correct)
self.assertEqual(decryptor.sanitize_filename("UPPERCASE.CIA"), "UPPERCASE.CIA")
# If all characters are invalid, it returns the original string
self.assertEqual(decryptor.sanitize_filename("!!!"), "!!!")

if __name__ == '__main__':
unittest.main()
info = decryptor.parse_ctrtool_output(text)
self.assertEqual(info.title_id, "0004000000000100")
self.assertEqual(info.title_version, "10")
self.assertEqual(info.crypto_key, "Crypto Key: Secure")
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.

2 participants