Restore Diff level working-tree change

- Add a dedicated native Diff fixture that commits baseline app.rb content and leaves an unstaged line-26 change from data.json to server.json.
- Update the Diff level setup metadata so app.rb is no longer represented as an empty file.
- Add a native runtime regression for `git diff` showing the expected line-26 hunk.
This commit is contained in:
Joe Tretter
2026-05-07 17:00:04 -05:00
parent 434bd8d97d
commit 7bfb761068
4 changed files with 78 additions and 3 deletions

View File

@@ -12,6 +12,7 @@ internal fun materializeNativeLevelFixture(
"branch_at" -> fixture.branchAt()
"checkout_tag" -> fixture.checkoutTag()
"checkout_tag_over_branch" -> fixture.checkoutTagOverBranch()
"diff" -> fixture.diff()
"fetch" -> fixture.fetch()
"pull" -> fixture.pull()
"push_branch" -> fixture.pushBranch()
@@ -176,6 +177,14 @@ private class NativeLevelFixture(
return true
}
fun diff(): Boolean {
resetFiles()
write("app.rb", diffLevelBaselineAppRb())
addCommit("Add app routes", "app.rb")
write("app.rb", diffLevelModifiedAppRb())
return true
}
fun pull(): Boolean {
resetFiles()
write("local_file")
@@ -387,3 +396,39 @@ private class NativeLevelFixture(
return true
}
}
internal fun diffLevelBaselineAppRb(): String = buildString {
appendLine("require 'sinatra'")
appendLine("require 'json'")
appendLine()
appendLine("helpers do")
appendLine(" def get_response(source)")
appendLine(" JSON.parse(File.read(source))['message']")
appendLine(" end")
appendLine("end")
appendLine()
appendLine("get '/' do")
appendLine(" @message = 'hello'")
appendLine(" erb :index")
appendLine("end")
appendLine()
appendLine("get '/page' do")
appendLine(" @message = 'page'")
appendLine(" erb :page")
appendLine("end")
appendLine()
appendLine("get '/yet_another' do")
appendLine(" @message = 'another'")
appendLine(" erb :success")
appendLine("end")
appendLine()
appendLine("get '/another_page' do")
appendLine(" @message = get_response('data.json')")
appendLine(" erb :another")
appendLine("end")
appendLine()
appendLine("# end of application")
}
internal fun diffLevelModifiedAppRb(): String =
diffLevelBaselineAppRb().replace("get_response('data.json')", "get_response('server.json')")

View File

@@ -13,7 +13,14 @@ internal fun diffLevel(): Level = level(
description = "Since your last commit, file `app.rb` was modified. Find out which line has changed.",
hints = listOf("You are looking for the difference since your last commit."),
commandSuggestions = listOf("git diff"),
setup = { RepoState(initialized = true, files = listOf(GitFile("app.rb", tracked = true)), branches = mapOf("master" to 1)) },
setup = {
RepoState(
initialized = true,
files = listOf(GitFile("app.rb", diffLevelModifiedAppRb(), tracked = true)),
commits = listOf(CommitNode("0000001", "Add app routes")),
branches = mapOf("master" to 1),
)
},
validator = commandAnswer("26"),
testCases = listOf(
levelTestCase("answer changed line", "26"),