-
Notifications
You must be signed in to change notification settings - Fork 0
feat: Implement Testing and Security Framework #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
12581cf
feat: Implement testing and security framework
AprilDeFeu 463ed78
Initial plan
Copilot 7b6aba8
fix: Resolve CI check failures in pre-commit configuration
Copilot 85cf201
Merge pull request #10 from AprilDeFeu/copilot/sub-pr-9
AprilDeFeu bf05752
Initial plan
Copilot 90d2a9b
fix: Address code review feedback - remove duplication, fix syntax
Copilot 5453590
Merge pull request #11 from AprilDeFeu/copilot/sub-pr-9
AprilDeFeu 7771b70
Initial plan
Copilot a3c6b51
Fix PowerShell test failures - handle empty MyDocuments path and fix …
Copilot 66f7b4b
Apply code review suggestions: add path validation and trim temp path…
Copilot 27184ac
Merge pull request #12 from AprilDeFeu/copilot/sub-pr-9
AprilDeFeu 605812e
Update .github/workflows/ci.yml
AprilDeFeu d34fa48
Update TESTING.md
AprilDeFeu 54d5221
Update tests/unit/PowerShell/system-maintenance.Tests.ps1
AprilDeFeu 28ab21e
Update .pre-commit-config.yaml
AprilDeFeu efb204c
Initial plan
Copilot c24e45a
Add comprehensive test examples demonstrating test coverage checklist
Copilot d434530
Merge pull request #13 from AprilDeFeu/copilot/sub-pr-9
AprilDeFeu 1e06243
Initial plan
Copilot 795d844
Merge pull request #14 from AprilDeFeu/copilot/sub-pr-9-again
AprilDeFeu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| --- | ||
| description: "Repo-specific instructions for GitHub Copilot" | ||
| applyTo: "**" | ||
| --- | ||
|
|
||
| # Copilot Instructions for the 'Scripts' Repository | ||
|
|
||
| When making changes to this repository, you MUST follow the established testing and security framework. | ||
|
|
||
| ## 1. Pre-Commit Hooks are Mandatory | ||
|
|
||
| This repository uses `pre-commit` to enforce code quality, formatting, and security checks. | ||
|
|
||
| - **After making ANY file modifications**, you MUST run the local linter to ensure your changes are compliant. Simulate this by stating you are running the command: | ||
| ```bash | ||
| pre-commit run --all-files | ||
| ``` | ||
| - If any hooks fail, you MUST fix the reported issues before proceeding. | ||
|
|
||
| ## 2. Testing is Required | ||
|
|
||
| All new scripts or modifications to existing scripts MUST be accompanied by tests. | ||
|
|
||
| - **Test Location:** Tests are located in the `tests/` directory, organized by unit, integration, etc., and then by language. | ||
| - Example: `tests/unit/PowerShell/` | ||
| - **PowerShell:** New PowerShell scripts require new Pester tests. Add them in the appropriate directory. | ||
| - **Running Tests:** To validate your changes, run the appropriate test command. For PowerShell, this is: | ||
| ```powershell | ||
| Invoke-Pester -Path 'tests/unit/PowerShell' | ||
| ``` | ||
|
|
||
| ## 3. Continuous Integration (CI) | ||
|
|
||
| - A CI workflow is located at `.github/workflows/ci.yml`. | ||
| - This pipeline automatically runs all `pre-commit` checks and all Pester tests. | ||
| - All changes must pass CI. Ensure your local checks are passing before you consider your task complete. | ||
|
|
||
| ## 4. Emphasize Edge Case Testing | ||
|
|
||
| As a repository focused on quality, all scripts must be robust. When creating or modifying scripts, you are expected to: | ||
|
|
||
| - **Identify and Test Edge Cases:** Explicitly consider and test for null inputs, empty strings, zero values, large inputs, and unexpected data types. | ||
| - **Validate and Sanitize All Inputs:** Assume all input is untrustworthy. | ||
| - **Ensure Graceful Failure:** Scripts should fail with clear, actionable error messages, especially for permission errors or missing dependencies. | ||
|
|
||
| ## 5. Adding New Languages | ||
|
|
||
| When adding a script for a new language (e.g., Python, Bash): | ||
|
|
||
| 1. **Update Pre-Commit:** Add the appropriate linter/formatter to `.pre-commit-config.yaml`. | ||
| - **Python:** Use `ruff` and `black`. | ||
| - **Bash:** `shellcheck` is already configured. | ||
| - **JavaScript/TypeScript:** Use `prettier` and `eslint`. | ||
| 2. **Add Test Scaffolding:** Create a new directory under `tests/unit/` for the language. | ||
| 3. **Add a Test File:** Implement a basic smoke test for the new script, including at least one edge case test. | ||
| 4. **Update CI:** Add a new job to `.github/workflows/ci.yml` to run the tests for the new language. | ||
|
|
||
| By following these rules, you will help maintain the quality, consistency, and security of this repository. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| # .github/workflows/ci.yml | ||
| name: CI | ||
|
|
||
| on: | ||
| push: | ||
| branches: [ main ] | ||
| pull_request: | ||
| branches: [ main ] | ||
| workflow_dispatch: | ||
|
|
||
| jobs: | ||
| lint: | ||
| name: Lint Codebase | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Checkout Code | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Set up Python | ||
| uses: actions/setup-python@v5 | ||
| with: | ||
| python-version: '3.11' | ||
|
|
||
| - name: Install pre-commit | ||
| run: pip install pre-commit | ||
|
|
||
| - name: Run pre-commit hooks | ||
| run: pre-commit run --all-files | ||
|
|
||
| test-powershell: | ||
| name: Test PowerShell | ||
| runs-on: windows-latest | ||
| steps: | ||
| - name: Checkout Code | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Install Pester | ||
| shell: pwsh | ||
| run: | | ||
| Install-Module -Name Pester -Force -SkipPublisherCheck | ||
|
|
||
| - name: Run Pester Tests | ||
| shell: pwsh | ||
| env: | ||
| SCRIPTS_ROOT: ${{ github.workspace }} | ||
| run: | | ||
| $result = Invoke-Pester -Path 'tests/unit/PowerShell' -PassThru | ||
| if ($result.FailedCount -gt 0) { | ||
| exit 1 | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,7 +13,7 @@ jobs: | |
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Install markdownlint | ||
| run: npm install --global [email protected] | ||
|
|
||
|
|
@@ -26,7 +26,7 @@ jobs: | |
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Validate PowerShell scripts | ||
| run: | | ||
| # Find PowerShell scripts and validate syntax | ||
|
|
@@ -36,13 +36,13 @@ jobs: | |
| # pwsh -NoProfile -NonInteractive -Command "& { try { [System.Management.Automation.PSParser]::Tokenize((Get-Content '$script' -Raw), [ref]\$null) | Out-Null; Write-Host 'OK: $script' } catch { Write-Error 'SYNTAX ERROR in $script: $_'; exit 1 } }" | ||
| done | ||
| continue-on-error: true | ||
|
|
||
| - name: Validate Python scripts | ||
| run: | | ||
| # Install Python and check syntax | ||
| python3 -m py_compile $(find . -name "*.py" -type f) || true | ||
| continue-on-error: true | ||
|
|
||
| - name: Validate Bash scripts | ||
| run: | | ||
| # Check bash scripts with shellcheck if available | ||
|
|
@@ -59,11 +59,11 @@ jobs: | |
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Validate repository structure | ||
| run: | | ||
| echo "Checking repository structure..." | ||
|
|
||
| # Check for required top-level files | ||
| required_files=("README.md" "LICENSE" "INSTRUCTIONS.md" "CONTRIBUTING.md") | ||
| for file in "${required_files[@]}"; do | ||
|
|
@@ -74,7 +74,7 @@ jobs: | |
| echo "✓ Found: $file" | ||
| fi | ||
| done | ||
|
|
||
| # Check for expected language directories | ||
| expected_dirs=("Bash" "Go" "JavaScript" "PowerShell" "Python" "Ruby") | ||
| for dir in "${expected_dirs[@]}"; do | ||
|
|
@@ -84,7 +84,7 @@ jobs: | |
| echo "✓ Found: $dir/" | ||
| fi | ||
| done | ||
|
|
||
| # Check category structure within language directories | ||
| categories=("automation" "data-processing" "miscellaneous" "networking" "system-administration" "text-processing" "web-scraping") | ||
| for lang_dir in "${expected_dirs[@]}"; do | ||
|
|
@@ -96,5 +96,5 @@ jobs: | |
| done | ||
| fi | ||
| done | ||
| echo "Repository structure validation complete" | ||
|
|
||
| echo "Repository structure validation complete" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| # See https://pre-commit.com for more information | ||
| # See https://pre-commit.com/hooks.html for more hooks | ||
| repos: | ||
| - repo: https://github.com/pre-commit/pre-commit-hooks | ||
| rev: v4.6.0 | ||
| hooks: | ||
| - id: trailing-whitespace | ||
| - id: end-of-file-fixer | ||
| - id: check-yaml | ||
| - id: check-json | ||
| - id: check-added-large-files | ||
| - repo: https://github.com/gitleaks/gitleaks | ||
| rev: v8.18.4 | ||
| hooks: | ||
| - id: gitleaks | ||
| - repo: https://github.com/igorshubovych/markdownlint-cli | ||
| rev: v0.41.0 | ||
| hooks: | ||
| - id: markdownlint | ||
| exclude: '^\.github/instructions/.*\.md$' | ||
| - repo: https://github.com/koalaman/shellcheck-precommit | ||
| rev: v0.10.0 | ||
| hooks: | ||
| - id: shellcheck | ||
| - repo: https://github.com/pre-commit/mirrors-prettier | ||
| rev: v3.1.0 | ||
| hooks: | ||
| - id: prettier | ||
| types: [yaml, json, markdown] | ||
| - repo: local | ||
| hooks: | ||
| - id: psscriptanalyzer | ||
| name: psscriptanalyzer | ||
| entry: pwsh -Command "Invoke-ScriptAnalyzer -Path PowerShell/ -Recurse -ExcludeRule PSAvoidUsingWriteHost" | ||
| language: system | ||
| types: [powershell] | ||
| pass_filenames: false |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing the closing brace
}for therunblock. The PowerShell script block that starts on line 45 is not properly closed, which will cause a workflow syntax error.Add the closing brace after line 49: