Skip to content

Commit dcb67ce

Browse files
matz3RandomByte
authored andcommitted
test(project): Assert delta build invalidation on dependency and source-map changes
Flip the previously test.failing cases to passing, as the underlying behavior now works: - Minify re-runs and writes the correct delta when only an input source map changes (ProjectBuilder.caching + BuildServer.buildSignature). - A custom task reacts to dependency content changes, so the application is rebuilt (ProjectBuilder.customTasks). The dependency-change fixture gets a determineRequiredDependencies hook so its reads are tracked. - validateCache refreshes dependency indices on a dependency-set change (ProjectBuildCache stale-index cases). Add writtenResources and skippedTasks assertions to pin down the exact delta behavior and guard against regressions.
1 parent c111d07 commit dcb67ce

5 files changed

Lines changed: 76 additions & 55 deletions

File tree

‎packages/project/test/fixtures/application.a/task.dependency-change.js‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,7 @@ module.exports = async function ({log, taskUtil, workspace}) {
3434
// Start processing dependencies of the root project
3535
await processProject(taskUtil.getProject());
3636
};
37+
38+
module.exports.determineRequiredDependencies = function ({availableDependencies}) {
39+
return availableDependencies;
40+
}

‎packages/project/test/lib/build/BuildServer.buildSignature.integration.js‎

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -69,17 +69,12 @@ test.serial.failing(
6969
"Served resource no longer reflects the stale control value v1");
7070
});
7171

72-
// Served counterpart of the ProjectBuilder minify source-map staleness test (see
72+
// Served counterpart of the ProjectBuilder minify source-map test (see
7373
// ProjectBuilder.caching.integration.js for the full mechanism). Minify reads a resource's input source
7474
// map via fsInterface and embeds its content into the `-dbg.js.map` output. That read goes through the
7575
// monitored workspace's byPath, so changing ONLY the `.js.map` (not the referencing `.js`) invalidates
76-
// minify's cache and re-runs it in delta mode with the `.js.map` as the sole changed path. But minify
77-
// keeps only changed `.js` paths, so the unchanged `.js` is filtered out, the task writes nothing, and
78-
// the previously served `-dbg.js.map` is carried forward STALE.
79-
//
80-
// This asserts the desired behavior (the changed input map is reflected in the served debug map without
81-
// a server restart) and is marked test.failing because the delta path does not yet achieve it. See the
82-
// minify FIXME for why a fix needs the `.map` -> `.js` relation, not a local pattern tweak.
76+
// minify's cache and re-runs it with the `.js.map` as the changed path. The served `-dbg.js.map` must
77+
// then reflect the new input map content without a server restart.
8378
test.serial(
8479
"Serve application.a, changing only an input source map read via fs by minify invalidates the debug source map",
8580
async (t) => {
@@ -99,7 +94,7 @@ test.serial(
9994

10095
// Change ONLY the input source map — NOT the referencing scriptWithSourceMap.js. The minify task
10196
// read this map via fsInterface, so it is a tracked input and this change invalidates minify's
102-
// cache. But the owning .js is unchanged, so the differential minify path has no .js to reprocess.
97+
// cache.
10398
const jsMapContent = await fs.readFile(jsMapFilePath, {encoding: "utf8"});
10499
await fs.writeFile(
105100
jsMapFilePath,
@@ -112,8 +107,7 @@ test.serial(
112107

113108
// #2 request: the served debug source map must reflect the changed input source map content.
114109
// The minify task is expected to re-execute here (its cache is invalidated because the changed
115-
// .js.map is a tracked input) — proving the staleness is a differential-execution defect, not a
116-
// missed invalidation.
110+
// .js.map is a tracked input).
117111
const second = await fixtureTester.requestResource({
118112
resource: dbgSourceMapResourcePath,
119113
assertions: {
@@ -127,8 +121,17 @@ test.serial(
127121
"enhanceManifest",
128122
"generateFlexChangesBundle",
129123
"generateVersionInfo"
130-
// "minify" is NOT skipped: it re-runs in differential mode for the changed .js.map
131-
]
124+
// "minify" is NOT skipped: it re-runs for the changed .js.map
125+
],
126+
writtenResources: {
127+
// Only resources affected by the source map change should be written
128+
"minify": [
129+
"/resources/id1/thirdparty/scriptWithSourceMap-dbg.js",
130+
"/resources/id1/thirdparty/scriptWithSourceMap-dbg.js.map",
131+
"/resources/id1/thirdparty/scriptWithSourceMap.js",
132+
"/resources/id1/thirdparty/scriptWithSourceMap.js.map",
133+
]
134+
}
132135
}
133136
}
134137
}

‎packages/project/test/lib/build/ProjectBuilder.caching.integration.js‎

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -358,18 +358,6 @@ test.serial("Build application.a project multiple times", async (t) => {
358358
});
359359
});
360360

361-
// Minify reads a resource's input source map (the `//# sourceMappingURL=` target) via fsInterface and
362-
// embeds its content almost verbatim into the `-dbg.js.map` output, so that debug map is a direct
363-
// function of the input map. The read is a tracked input, so changing ONLY the `.js.map` (not the `.js`
364-
// that references it) invalidates minify's cache and re-runs it in delta mode with the `.js.map` as the
365-
// sole changed path. But minify keeps only changed `.js` paths and reads input maps only as a side
366-
// effect of processing their owning `.js`; the unchanged `.js` is filtered out, so the task writes
367-
// nothing and the previously produced `-dbg.js.map` is carried forward STALE.
368-
//
369-
// This asserts the desired behavior (the changed input map is reflected in the built debug map) and is
370-
// marked test.failing because the delta path does not yet achieve it. See BuildServer.integration.js for
371-
// the same scenario over the served build, and the minify FIXME for why a fix needs the `.map` -> `.js`
372-
// relation, not a local pattern tweak.
373361
test.serial(
374362
"Build application.a, changing only an input source map read via fs by minify invalidates the debug source map",
375363
async (t) => {
@@ -389,9 +377,7 @@ test.serial(
389377
t.true(firstContent.includes("This is a script with a source map."),
390378
"Initial debug source map reflects the original input source map content");
391379

392-
// Change ONLY the input source map — NOT the referencing scriptWithSourceMap.js. The minify task
393-
// read this map via fsInterface, so it is a tracked input and this change invalidates minify's
394-
// cache. But the owning .js is unchanged, so the differential minify path has no .js to reprocess.
380+
// Change ONLY the input source map — NOT the referencing scriptWithSourceMap.js.
395381
const jsMapContent = await fs.readFile(jsMapFilePath, {encoding: "utf8"});
396382
await fs.writeFile(
397383
jsMapFilePath,
@@ -402,9 +388,7 @@ test.serial(
402388
);
403389

404390
// #2 build (with cache, with changes): the built debug source map must reflect the changed input
405-
// source map content. The minify task is expected to re-execute here (its cache is invalidated
406-
// because the changed .js.map is a tracked input) — proving the staleness is a differential-
407-
// execution defect, not a missed invalidation.
391+
// source map content. The minify task is expected to re-execute here
408392
await fixtureTester.buildProject({
409393
config: {destPath, cleanDest: true},
410394
assertions: {
@@ -418,9 +402,18 @@ test.serial(
418402
// replaceCopyright is skipped because no copyright is configured in the project
419403
"replaceCopyright",
420404
// replaceVersion has no work for the changed .js.map and is skipped
421-
"replaceVersion"
422-
// "minify" is NOT skipped: it re-runs in differential mode for the changed .js.map
423-
]
405+
"replaceVersion",
406+
// "minify" is NOT skipped: it re-runs for the changed .js.map
407+
],
408+
writtenResources: {
409+
// Only resources affected by the source map change should be written
410+
"minify": [
411+
"/resources/id1/thirdparty/scriptWithSourceMap-dbg.js",
412+
"/resources/id1/thirdparty/scriptWithSourceMap-dbg.js.map",
413+
"/resources/id1/thirdparty/scriptWithSourceMap.js",
414+
"/resources/id1/thirdparty/scriptWithSourceMap.js.map",
415+
]
416+
}
424417
}
425418
}
426419
}

‎packages/project/test/lib/build/ProjectBuilder.customTasks.integration.js‎

Lines changed: 40 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -236,30 +236,31 @@ test.serial("Build application.a (multiple custom tasks 2)", async (t) => {
236236
});
237237
});
238238

239-
test.serial.failing("Build application.a (dependency content changes)", async (t) => {
239+
test.serial("Build application.a (dependency content changes)", async (t) => {
240240
const fixtureTester = new FixtureTester(t, "application.a");
241241
const destPath = fixtureTester.destPath;
242242

243243
// Scenario: A custom task reads dependency resources via taskUtil.getProject().getReader() and conditionally
244244
// modifies application resources based on what it finds. When the dependency content changes, the application
245245
// should be rebuilt so the custom task can react to the new dependency state. The assertions below encode that
246246
// desired behavior.
247-
//
248-
// Marked test.failing because it currently fails: the custom task accesses dependencies through
249-
// taskUtil.getProject("library.d").getReader() rather than the monitored "dependencies" reader parameter. Reads
250-
// through this path are not tracked by the caching system's ResourceRequestManager, so dependency changes don't
251-
// invalidate the application's result cache. AVA reports a failing-marked test as a pass while it throws and as a
252-
// hard error once it starts passing, so committing it keeps CI green and flips to a signal the moment the behavior
253-
// is fixed (at which point drop the `.failing`).
254-
// Fixing this requires tracking reads made via taskUtil.getProject().getReader() as dependency requests.
255247

256248
// #1 build (no cache, no changes, no dependencies)
257249
await fixtureTester.buildProject({
258250
graphConfig: {rootConfigPath: "ui5-customTask-dependency-change.yaml"},
259251
config: {destPath, cleanDest: true},
260252
assertions: {
261253
projects: {
262-
"application.a": {}
254+
"library.d": {},
255+
"library.a": {},
256+
"library.b": {},
257+
"library.c": {},
258+
"application.a": {
259+
writtenResources: {
260+
// No resources are written as no newLibraryFile.js in library.d exists yet.
261+
"dependency-change": [],
262+
}
263+
}
263264
}
264265
}
265266
});
@@ -285,10 +286,14 @@ test.serial.failing("Build application.a (dependency content changes)", async (t
285286
config: {destPath, cleanDest: true, dependencyIncludes: {includeAllDependencies: true}},
286287
assertions: {
287288
projects: {
288-
"library.d": {},
289-
"library.a": {},
290-
"library.b": {},
291-
"library.c": {},
289+
"library.d": {
290+
skippedTasks: [
291+
"buildThemes",
292+
"enhanceManifest",
293+
"escapeNonAsciiCharacters",
294+
"replaceBuildtime",
295+
]
296+
},
292297
}
293298
}
294299
});
@@ -307,17 +312,35 @@ test.serial.failing("Build application.a (dependency content changes)", async (t
307312
// and modifies a resource of application.a (namely "test.js").
308313
await fixtureTester.buildProject({
309314
graphConfig: {rootConfigPath: "ui5-customTask-dependency-change.yaml"},
310-
config: {destPath, cleanDest: true, dependencyIncludes: {includeAllDependencies: true}},
315+
config: {
316+
destPath, cleanDest: true, dependencyIncludes: {includeAllDependencies: true},
317+
},
311318
assertions: {
312319
projects: {
313-
"library.d": {},
320+
"library.d": {
321+
skippedTasks: [
322+
"buildThemes",
323+
"enhanceManifest",
324+
"escapeNonAsciiCharacters",
325+
"replaceBuildtime",
326+
]
327+
},
314328
"application.a": {
315329
skippedTasks: [
316330
"enhanceManifest",
317331
"escapeNonAsciiCharacters",
332+
"generateComponentPreload",
318333
"generateFlexChangesBundle",
334+
"generateVersionInfo",
335+
"minify",
319336
"replaceCopyright",
320-
]
337+
"replaceVersion",
338+
// dependency-change task is expected to run
339+
],
340+
writtenResources: {
341+
// /test.js is written when a newLibraryFile.js in the dependency library.d exists.
342+
"dependency-change": ["/test.js"],
343+
}
321344
},
322345
}
323346
}

‎packages/project/test/lib/build/cache/ProjectBuildCache.js‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2578,10 +2578,8 @@ test("Fail-then-succeed: delta merge does not resurrect resources from a stage a
25782578
// signature the cache reports afterwards is compared against the signature a full refresh against
25792579
// the new set produces (computed independently via ResourceRequestManager).
25802580
//
2581-
// They are marked test.failing: they assert the *desired* behavior and currently fail because the
2582-
// bug is unfixed. AVA reports a failing-marked test as a pass while it throws and as a hard error
2583-
// once it starts passing, so committing them keeps CI green and flips to a signal the moment the
2584-
// fix lands (at which point drop the `.failing`).
2581+
// validateCache now refreshes the dependency indices on a dependency-set change, so these cases
2582+
// pass and guard against a regression of the stale-index bug.
25852583

25862584
// Builds a persisted "dependencies" task-metadata object by recording a single glob request
25872585
// against `oldDepResources`, mirroring what a real build stores for a task that globs dependency

0 commit comments

Comments
 (0)