引導式測驗 · 硬 等級

如何使用 AI 測驗重構遺留程式碼

透過建立基準、進行小的變更和測試邊緣情況,使用 AI 實踐行為保留重構。

問題 1 的 8

A legacy function has no written specification. What should a team capture before changing its structure?

預覽每個問題8 問題

當您參加測驗時,就會出現答案和解釋。

  1. A legacy function has no written specification. What should a team capture before changing its structure?
    • Current observable behavior with tests or representative fixtures
    • Only the model’s summary of what the function should do
    • A shorter replacement implementation
    • The number of lines removed
  2. An AI proposal both extracts a helper and changes how malformed input is handled. What is the safest review plan?
    • Merge both because the new code is cleaner
    • Delete the malformed-input tests
    • Assume the behavior change is required by refactoring
    • Separate the structural refactor from the behavior change and review each on its own
  3. Why is a model-generated test not automatically proof that a refactor is safe?
    • Tests cannot be run after refactoring
    • It may encode the same mistaken assumption as the generated implementation
    • AI-generated tests always fail
    • A test suite makes behavior irrelevant
  4. A refactor changes iteration order for returned records, and a downstream client depends on that order. Which risk did the change expose?
    • Only the function’s internal naming changed
    • The source file became easier to navigate
    • An observable behavior or compatibility contract may have changed
    • The tests now run faster
  5. Which work pattern best limits risk when asking AI to refactor an unfamiliar module?
    • One small transformation, full diff review and focused tests before the next step
    • A complete rewrite followed by one final test run
    • Accept every suggestion and review only changed filenames
    • Combine feature work and cleanup in one opaque patch
  6. A test calls a live external service whose response changes over time. What can make the characterization test more dependable?
    • Increase the number of retries until it passes
    • Remove all assertions
    • Ask AI to predict the service’s next response
    • Use a deterministic test double or recorded fixture for the external interaction
  7. After helper extraction, the focused tests pass. What should happen before merging?
    • Assume every possible behavior is preserved
    • Run broader checks and inspect compatibility, side effects and representative edge cases
    • Skip review because the diff is small
    • Delete tests that document old behavior
  8. A reviewer finds that “cleaned up” code now logs less information on failures. What is the relevant next question?
    • Whether the assistant used a modern syntax feature
    • Whether the refactor reduced line count
    • Whether logging is an observable operational behavior the system needs to preserve
    • Whether comments can be generated automatically