|
| 1 | +/** |
| 2 | + * Regression gate for the 4.0.6 first-boot EmptyStackException on |
| 3 | + * Adobe CF 2023 + CommandBox (issue ##3379, separate from the torn-down |
| 4 | + * application.wo / onError String[] stacks on that same issue). |
| 5 | + * |
| 6 | + * Field stack: onapplicationstart.cfc:409 `$createObjectFromRoot` → |
| 7 | + * Public.$init → Adobe `NeoPageContext.popSuperScope` EmptyStack. 4.0.5 |
| 8 | + * Public.$init is include helpers + return only. 4.0.6 and develop call |
| 9 | + * `$scanAndPromoteIncludedGlobals()` (a parent-class method on Global) |
| 10 | + * immediately after the raw `include` in the same `$init` body. Adobe's |
| 11 | + * first compile of helpers.cfm after a cold start unbalances the |
| 12 | + * super-scope stack; a later request succeeds. |
| 13 | + * |
| 14 | + * This VM cannot run Adobe CF 2023 + CommandBox, so the field EmptyStack |
| 15 | + * cannot be reproduced here. What CI can prove: |
| 16 | + * 1. `$init` does not throw on the LuCLI engine. |
| 17 | + * 2. The ##3302 promote still lands helpers.cfm UDFs on `this`. |
| 18 | + * 3. The promote scan runs after `$includePublicHelpers` returns — not |
| 19 | + * nested inside the same method as the raw include. |
| 20 | + * 4. `$init`'s own body contains no raw `include` statement, so the |
| 21 | + * nest cannot silently return. |
| 22 | + */ |
| 23 | +component extends="wheels.WheelsTest" { |
| 24 | + |
| 25 | + function run() { |
| 26 | + |
| 27 | + var ctx = {fixturePath: "wheels.tests._assets.global.PublicInitTraceFixture"}; |
| 28 | + |
| 29 | + describe("Public.$init include/promote un-nest (issue ##3379 first-boot EmptyStack)", () => { |
| 30 | + |
| 31 | + it("Public.$init does not throw", () => { |
| 32 | + var state = {threw = false, message = ""}; |
| 33 | + try { |
| 34 | + var publicCfc = CreateObject("component", "wheels.Public"); |
| 35 | + publicCfc.$init(); |
| 36 | + } catch (any e) { |
| 37 | + state.threw = true; |
| 38 | + state.message = e.message; |
| 39 | + } |
| 40 | + expect(state.threw).toBeFalse( |
| 41 | + "Public.$init threw: " & state.message |
| 42 | + ); |
| 43 | + }); |
| 44 | + |
| 45 | + it("still promotes helpers.cfm functions onto this (##3302 contract)", () => { |
| 46 | + var publicCfc = CreateObject("component", "wheels.Public"); |
| 47 | + publicCfc.$init(); |
| 48 | + expect(StructKeyExists(publicCfc, "$$findMatchingRoutes")).toBeTrue( |
| 49 | + "expected $$findMatchingRoutes from helpers.cfm on this after $init" |
| 50 | + ); |
| 51 | + expect(IsCustomFunction(publicCfc["$$findMatchingRoutes"])).toBeTrue(); |
| 52 | + expect(StructKeyExists(publicCfc, "pageHeader")).toBeTrue( |
| 53 | + "expected pageHeader from helpers.cfm on this after $init" |
| 54 | + ); |
| 55 | + expect(IsCustomFunction(publicCfc.pageHeader)).toBeTrue(); |
| 56 | + }); |
| 57 | + |
| 58 | + it("the $createObjectFromRoot boot path still returns a promoted Public instance", () => { |
| 59 | + var publicCfc = application.wo.$createObjectFromRoot( |
| 60 | + path = "wheels", |
| 61 | + fileName = "Public", |
| 62 | + method = "$init" |
| 63 | + ); |
| 64 | + expect(IsObject(publicCfc)).toBeTrue(); |
| 65 | + expect(StructKeyExists(publicCfc, "$$findMatchingRoutes")).toBeTrue(); |
| 66 | + expect(IsCustomFunction(publicCfc["$$findMatchingRoutes"])).toBeTrue(); |
| 67 | + }); |
| 68 | + |
| 69 | + it("promote runs after $includePublicHelpers returns, not mid-include", () => { |
| 70 | + var fixture = CreateObject("component", ctx.fixturePath); |
| 71 | + fixture.$resetInitTrace(); |
| 72 | + fixture.$init(); |
| 73 | + var trace = fixture.$getInitTrace(); |
| 74 | + expect(ArrayLen(trace)).toBe( |
| 75 | + 3, |
| 76 | + "expected [include-start, include-return, promote], got [" & ArrayToList(trace) & "]" |
| 77 | + ); |
| 78 | + expect(trace[1]).toBe("include-start"); |
| 79 | + expect(trace[2]).toBe("include-return"); |
| 80 | + expect(trace[3]).toBe("promote"); |
| 81 | + }); |
| 82 | + |
| 83 | + it("$init body contains no raw include (structural nest guard)", () => { |
| 84 | + var filePath = ExpandPath("/wheels/Public.cfc"); |
| 85 | + var content = FileRead(filePath); |
| 86 | + var fileLines = ListToArray(content, Chr(10), true); |
| 87 | + var inInit = false; |
| 88 | + var offenders = []; |
| 89 | + var lineNumber = 0; |
| 90 | + for (var rawLine in fileLines) { |
| 91 | + lineNumber++; |
| 92 | + var trimmed = Trim(Replace(rawLine, Chr(13), "", "all")); |
| 93 | + if (ReFindNoCase("function\s+\$init\s*\(", trimmed)) { |
| 94 | + inInit = true; |
| 95 | + continue; |
| 96 | + } |
| 97 | + if (inInit && ReFindNoCase("function\s+\$includePublicHelpers\s*\(", trimmed)) { |
| 98 | + break; |
| 99 | + } |
| 100 | + if (inInit && ReFindNoCase("(public|private|package|remote)?\s*(any|void|struct|array|string|boolean|numeric|query|date)?\s*function\s+", trimmed)) { |
| 101 | + break; |
| 102 | + } |
| 103 | + if (!inInit) { |
| 104 | + continue; |
| 105 | + } |
| 106 | + if (Left(trimmed, 2) == "//" || Left(trimmed, 1) == "*" || Left(trimmed, 2) == "/*") { |
| 107 | + continue; |
| 108 | + } |
| 109 | + if (ReFindNoCase("^\s*include\s+", trimmed)) { |
| 110 | + ArrayAppend(offenders, "raw include at line " & lineNumber); |
| 111 | + } |
| 112 | + } |
| 113 | + expect(inInit).toBeTrue("expected to find Public.$init in Public.cfc"); |
| 114 | + expect(ArrayLen(offenders)).toBe( |
| 115 | + 0, |
| 116 | + "Public.$init must not contain a raw include (nest with promote scan): " & ArrayToList(offenders) |
| 117 | + ); |
| 118 | + }); |
| 119 | + |
| 120 | + }); |
| 121 | + } |
| 122 | + |
| 123 | +} |
0 commit comments