Bài kiểm tra có liên kết hướng dẫn · Cứng Cấp độ

Cách tái cấu trúc mã kế thừa bằng AI Quiz

Thực hành tái cấu trúc bảo toàn hành vi bằng AI bằng cách thiết lập các đường cơ sở, thực hiện các thay đổi nhỏ và thử nghiệm các trường hợp đặc biệt.

Đường dẫn hướng dẫn liên quanCách cấu trúc lại mã kế thừa bằng AI
Câu hỏi 1 của 8

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

Xem trước mọi câu hỏi8 câu hỏi

Câu trả lời và giải thích xuất hiện khi bạn làm bài kiểm tra.

  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