safe-code-change

作成者: openshift

コード変更後、影響を受けるテストを見つけ、新しい動作に合わせて更新し、ユーザーに検証の実行を促します。ユーザーが変更を行ったか、依頼した場合に使用します。

npx skills add https://github.com/openshift/lightspeed-operator --skill safe-code-change

Safe Code Change

After a code change is made, find and fix affected tests before running validation.

Rules

  • The code change is already done. Do not modify production code.
  • Only update tests to match the new behavior, not the other way around.
  • Do not reformat or lint-fix during test updates. Save that for validation.
  • If a test change is ambiguous (unclear what the new expected behavior is), ask the user.

Step 1: Identify What Changed

git diff --name-only
git diff --stat

List the modified production files (ignore test files, configs, docs).

Step 2: Find Affected Tests

Search for imports and uses of changed functions/types across all test files:

# Find test files that import the changed package
rg "github.com/openshift/lightspeed-operator/<changed_package>" --type go -g '*_test.go'

# Find direct function/type references
rg "<ChangedFunctionOrType>" --type go -g '*_test.go'

For controller changes, also check:

  • internal/controller/suite_test.go (shared test setup)
  • test/e2e/ (E2E tests)

Step 3: Analyze Impact on Tests

For each affected test file, check whether the change breaks existing tests:

  1. Signature changes — function renamed, parameters added/removed/reordered.
  2. Behavior changes — return value, error messages, side effects differ.
  3. Removed code — tests for deleted functions/types need removal.
  4. New code — consider whether new tests are needed (ask user if unclear).
  5. Interface changes — mock implementations need updating.

Step 4: Update Tests

Apply minimal fixes to each affected test:

For Ginkgo Tests (most controller tests):

  • Update Expect() assertions to match new return values
  • Update mock return values in test fixtures
  • Add/remove parameters in function calls
  • Update error message checks
  • Adjust Eventually() timeouts if reconciliation logic changed

For Standard Go Tests (utils, helpers):

  • Update table-driven test cases with new expected values
  • Update mock implementations
  • Add/remove parameters in function calls
  • Update error assertions

Common Fixes:

  • Error constant renamed: Update all Expect(err).To(MatchError(ContainSubstring(oldName)))newName
  • Function signature changed: Update all call sites in tests
  • Resource structure changed: Update test fixtures and expected values
  • Owner reference logic changed: Update assertions that check OwnerReferences

Step 5: Verify Test File Syntax

Before telling the user tests are ready, verify Go syntax:

go fmt <modified_test_file>

If formatting changes the file significantly, there may be syntax errors.

Step 6: Report

List all test files updated and what was changed in each:

  1. File name
  2. What was updated (function calls, expectations, mocks, fixtures)
  3. Number of changes

Then guide the user to run validation:

Tests are updated. Run validation with:
  make test          # Run all unit tests
  make test-e2e      # Run E2E tests (requires cluster)
  make lint          # Check code style

If tests fail, review the specific failures and adjust expectations.

Do not run make test automatically — let the user control when tests run.

openshiftのその他のスキル

openshift-expert
openshift
OpenShiftプラットフォームとKubernetesのエキスパートであり、クラスターアーキテクチャ、オペレーター、ネットワーキング、ストレージ、トラブルシューティング、CI/CDパイプラインに関する深い知識を持つ。使用…
official
find-token
openshift
隠された認証トークンを見つけます。find-tokenスクリプトを実行して、ユニークなトークンを取得します。
official
code-review
openshift
プルリクエストのコード品質、正確性、プロジェクト規約をレビューします。ユーザーがPRのレビュー、コードレビュー、または変更の確認を依頼した場合に使用します。
official
css-review
openshift
CSSのコーディングスタイル、PatternFlyトークンの使用法、ベストプラクティスをレビューします。ユーザーがCSSのレビュー、スタイルの確認、CSSファイルの監査を依頼した場合に使用します。
official
review-readmes
openshift
リポジトリ内のすべてのREADME.mdファイルをレビューし、タイポ、エラー、古い情報をチェックします。ユーザーがREADMEのレビューやドキュメントの正確性の確認などを依頼したときに使用します。
official
review-skills
openshift
プロジェクトのAIスキルを重複、古い参照、誤り、構造上の問題についてレビューします。ユーザーがスキルのレビュー、監査、チェックを依頼した場合に使用します。
official
test
openshift
タグでフィルタリングされたエンドツーエンドテストを実行します。ユーザーがテストの実行、Playwrightの実行、または@coreや@attachのような特定の機能タグのテストを依頼した場合に使用します。
official
unused-exports
openshift
他のファイルから一度もインポートされていないエクスポートされたシンボルを検出します。ユーザーが「エクスポートを確認」「未使用のエクスポート」と言ったり、エクスポートの整理を依頼した場合に使用します。
official