mirror of
https://github.com/trailofbits/algo.git
synced 2026-08-25 09:02:30 +02:00
* ci: modernize tooling with prek, ty, and security scanning Migrate from pre-commit to prek (Rust-native, faster hooks) and add comprehensive CI improvements for code quality and security. Changes: - Replace pre-commit with prek for git hooks - Add ty type checker (Rust-based, replaces mypy) - Expand ruff rules: security (S), simplify (SIM), commented code (ERA) - Add pip-audit workflow for Python dependency CVE scanning - Add actionlint and zizmor for GitHub Actions linting/security - Add ruff format check to CI - Enable stricter ansible-lint rules (no-changed-when, risky-file-permissions) - Remove obsolete Claude workflow files - Apply ruff formatting fixes to test files Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix(ci): resolve actionlint install and ty type errors - Use actionlint's official install script instead of broken URL pattern - Exclude test mock modules from ty type checking - Run workflows on push only for main/master to avoid duplicate PR runs Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix(ci): use glob pattern for actionlint, exclude all tests from ty - actionlint requires *.yml glob, not directory path - Exclude all tests from ty type checking (test code has looser typing) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix(ci): quote shell variables to fix shellcheck warnings Fix SC2046/SC2086 warnings in workflow scripts: - Quote $(uname -r) in apt-get install - Quote $(pwd) in docker volume mount - Quote $existing in gh issue comment Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix(ci): move key-order[task] to warn_list Too many existing violations in the codebase to enable as error. Move to warn_list for gradual fixes over time. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
137 lines
4.7 KiB
Python
137 lines
4.7 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Test Scaleway role fixes for issue #14846
|
|
|
|
This test validates that:
|
|
1. The Scaleway role uses the modern 'project' parameter instead of deprecated 'organization'
|
|
2. The Marketplace API is used for image lookup instead of the broken scaleway_image_info module
|
|
3. The prompts include organization/project ID collection
|
|
"""
|
|
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
import yaml
|
|
|
|
|
|
def load_yaml_file(file_path):
|
|
"""Load and parse a YAML file"""
|
|
with open(file_path) as f:
|
|
return yaml.safe_load(f)
|
|
|
|
|
|
def test_scaleway_main_uses_project_parameter():
|
|
"""Test that main.yml uses 'project' instead of deprecated 'organization' parameter"""
|
|
main_yml = Path("roles/cloud-scaleway/tasks/main.yml")
|
|
assert main_yml.exists(), "Scaleway main.yml not found"
|
|
|
|
with open(main_yml) as f:
|
|
content = f.read()
|
|
|
|
# Should NOT use the broken scaleway_organization_info module
|
|
assert "scaleway_organization_info" not in content, (
|
|
"Still using broken scaleway_organization_info module (issue #14846)"
|
|
)
|
|
|
|
# Should NOT use the broken scaleway_image_info module
|
|
assert "scaleway_image_info" not in content, "Still using broken scaleway_image_info module"
|
|
|
|
# Should use project parameter (modern approach)
|
|
assert "project:" in content, "Missing 'project:' parameter in scaleway_compute calls"
|
|
assert "algo_scaleway_org_id" in content, "Missing algo_scaleway_org_id variable reference"
|
|
|
|
# Should NOT use deprecated organization parameter
|
|
assert 'organization: "{{' not in content, "Still using deprecated 'organization' parameter"
|
|
|
|
# Should use Marketplace API for image lookup
|
|
assert "api-marketplace.scaleway.com" in content, "Not using Scaleway Marketplace API for image lookup"
|
|
|
|
print("✓ Scaleway main.yml uses modern 'project' parameter")
|
|
|
|
|
|
def test_scaleway_prompts_collect_org_id():
|
|
"""Test that prompts.yml collects organization/project ID from user"""
|
|
prompts_yml = Path("roles/cloud-scaleway/tasks/prompts.yml")
|
|
assert prompts_yml.exists(), "Scaleway prompts.yml not found"
|
|
|
|
with open(prompts_yml) as f:
|
|
content = f.read()
|
|
|
|
# Should prompt for organization ID
|
|
assert "Organization ID" in content, "Missing prompt for Scaleway Organization ID"
|
|
|
|
# Should set algo_scaleway_org_id fact
|
|
assert "algo_scaleway_org_id:" in content, "Missing algo_scaleway_org_id fact definition"
|
|
|
|
# Should support SCW_DEFAULT_ORGANIZATION_ID env var
|
|
assert "SCW_DEFAULT_ORGANIZATION_ID" in content, (
|
|
"Missing support for SCW_DEFAULT_ORGANIZATION_ID environment variable"
|
|
)
|
|
|
|
# Should mention console.scaleway.com for finding the ID
|
|
assert "console.scaleway.com" in content, "Missing instructions on where to find Organization ID"
|
|
|
|
print("✓ Scaleway prompts.yml collects organization/project ID")
|
|
|
|
|
|
def test_scaleway_config_has_valid_settings():
|
|
"""Test that config.cfg has valid Scaleway settings"""
|
|
config_file = Path("config.cfg")
|
|
assert config_file.exists(), "config.cfg not found"
|
|
|
|
with open(config_file) as f:
|
|
content = f.read()
|
|
|
|
# Should have scaleway section
|
|
assert "scaleway:" in content, "Missing Scaleway configuration section"
|
|
|
|
# Should specify Ubuntu 22.04
|
|
assert "Ubuntu 22.04" in content or "ubuntu" in content.lower(), "Missing Ubuntu image specification"
|
|
|
|
print("✓ config.cfg has valid Scaleway settings")
|
|
|
|
|
|
def test_scaleway_marketplace_api_usage():
|
|
"""Test that the role correctly uses Scaleway Marketplace API"""
|
|
main_yml = Path("roles/cloud-scaleway/tasks/main.yml")
|
|
|
|
with open(main_yml) as f:
|
|
content = f.read()
|
|
|
|
# Should use uri module to fetch from Marketplace API
|
|
assert "uri:" in content, "Not using uri module for API calls"
|
|
|
|
# Should filter for Ubuntu 22.04 Jammy
|
|
assert "Ubuntu" in content and "22" in content, "Not filtering for Ubuntu 22.04 image"
|
|
|
|
# Should set scaleway_image_id variable
|
|
assert "scaleway_image_id" in content, "Missing scaleway_image_id variable for image UUID"
|
|
|
|
print("✓ Scaleway role uses Marketplace API correctly")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
tests = [
|
|
test_scaleway_main_uses_project_parameter,
|
|
test_scaleway_prompts_collect_org_id,
|
|
test_scaleway_config_has_valid_settings,
|
|
test_scaleway_marketplace_api_usage,
|
|
]
|
|
|
|
failed = 0
|
|
for test in tests:
|
|
try:
|
|
test()
|
|
except AssertionError as e:
|
|
print(f"✗ {test.__name__} failed: {e}")
|
|
failed += 1
|
|
except Exception as e:
|
|
print(f"✗ {test.__name__} error: {e}")
|
|
failed += 1
|
|
|
|
if failed > 0:
|
|
print(f"\n{failed} tests failed")
|
|
sys.exit(1)
|
|
else:
|
|
print(f"\nAll {len(tests)} tests passed!")
|