Repository navigation
feat(mock): answer a recorded SAS session - #1575
Conversation
Coverage ratchetCompared against the baseline published for the base commit cbd3ccb.
No metric is below the base. |
66307db to
e336b59
Compare
There was a problem hiding this comment.
Reviewed PR #1575 at e336b59: the transcript lookup and its call site in src/commands/build/internal/mockSite/assets/sw.js, the build copy in mockSite.ts, the three specs, and the commit subject. Ten of the 11 check runs at this head are green; windows was still in progress, so this is code review plus one probe run locally against the real worker.
- src/commands/build/internal/mockSite/assets/sw.js:596-599
// project that ships no recording still has its SAS programs refused, by the/// runner rather than by the route, with the same message.- neither half holds. WithrunTimes: ['js', 'sas'](:598) the runtime route no longer refuses a .sas program, and runtime-core.js:1002-1011 resolves the .sas file from the drive and hands its text tonew Function, so SAS source is compiled as JavaScript. Probed at this head with a .sas program the transcript does not name: status 400,{"status":"failure","message":"Job execution failed.","error":"SyntaxError: Unexpected identifier 'work' ... at new Function"}. Before this change the package refused it with"runTime" must be one of [js]- the message the route builds at @sasjs/api build/esm/runtime/service.js:191-192. A project shipping no recording, which is the normal case, now gets a JavaScript SyntaxError quoting a line of its SAS program instead of a refusal. KeeprunTimes: ['js']and answer the recording ahead of the run-time check (a transcript is data, not a run time), or branch in the runner: if the program is .sas and no recording names it, throw the documented refusal. Add the negative case either way - both new specs assert only the recorded path, so nothing pins what an unrecorded .sas run answers. - src/commands/build/internal/mockSite/assets/sw.js:279-287
const name = (value) =>...value.split('/').pop().replace(/\.sas$/i, '')- the fallback matches on file name alone, so any program calledreport.sasanywhere in the drive is answered with a recording made for a different file, including one the recording does not name. The docstring above (:50-52) presents the recording as naming specific programs; a basename match widens that to every file of the same name. Drop the fallback (the exact-path lookup at :77 already matches what the demo build ships) or key it to the appLoc.
2 findings above for review.
|
Both findings were right, and the first was serious: with The run time. The unrecorded case needed one more piece: the request may name the program without its extension, so the runner could not tell it was SAS - which is why my first attempt at this still compiled it. The runtime now exposes The match. File-name matching is gone. A recording is matched on the logical drive path - mount prefix and Suite: 163 tests in |
e336b59 to
457bfbc
Compare
The demo told a visitor that Run on a .sas program needs a server, which was true and useless: the page exists to show what a Studio run looks like, and a refusal shows none of it. This ships the recording of one session - mock/sas-transcript.json - and makes the demo's program.sas the program that recording ran, so the source in the editor and the output in the panes are the same run. A visitor sees a log with notes, warnings and two errors, a two-page listing, and a webout with the full ms_webout.sas field set. The recording is the output of a real session with the "Licensed to ..., Site ..." line removed; SYSSITE is 00000000 and the host names are generic, so nothing in it identifies a licensee or a machine. Only the program the recording names is answered: any other .sas program is refused exactly as before, with the message a client already understands. The host answers from data the project ships and invents nothing. The CLI half (sasjs/cli#1575) copies sasjsbuild/sas-transcript.json into the site and answers a run with its three parts; until that release the file travels with the build and is unused.
There was a problem hiding this comment.
Re-review at 457bfbc. The branch was rewritten since e336b59 - a single commit on cbd3ccb - so the whole diff is the surface again and this supersedes the review at e336b59. Both findings from that review are closed: runTimes is back to ['js'] (sw.js:595) and the file-name fallback is gone, the lookup matching on the logical path only (sw.js:281-305). Check runs at this head: 11, all green. Not run locally (no node_modules on this box). I did check the refusal against @sasjs/api 0.23.0's runtime service: prepare hands the runner {path} (program.code is absent), and runTimeForPath returns 'sas' from the extension without consulting runTimes, so the refusal in the host at sw.js:319-322 is the only thing between an unrecorded .sas run and the JavaScript runner - it does fire, since program.path is set and program.code is not.
-
src/commands/build/internal/mockSite/assets/sw.js:941
if (!code) {- the branch answers every non-code run route, including/stp/trigger. A trigger of a recorded program therefore returns the framed webout/log/listing as a 200text/plainbody where the route otherwise returnsjson(answer, 200)with the session record (sw.js:958-966) - the adapter's triggerProgram and the Studio both parse that answer as JSON, so triggering the demo's program now fails to parse instead of returning a sessionId. Gate the branch on!triggerso a trigger keeps its previous answer, or return the record the trigger route builds; either way pin it, because neither new spec drives a trigger. -
Commit body,
A project may now ship sasjs-transcript.json, the recording of one session.- the file the code reads issas-transcript.json(sw.js:251, mockSite.ts:904, and the same name in sasjs/server's mock/). A project following this line ships a file nothing reads, and the commit body is the only documentation of the feature - there is no README or doc mention of the transcript anywhere in the tree. Correct the name in the message.
2 findings above for review.
457bfbc to
b9c1c7e
Compare
|
Both fixed at b9c1c7e. The trigger. Right, and it would have broken The file name. Also right, and worse than a typo: On the documentation point: there is no prose docs tree in this repo - Suite: 164 tests in the mock site specs, 163 pass - the single failure is the pre-existing Admin-diagnostics one that also fails on clean |
The demo told a visitor that Run on a .sas program needs a server, which was true and useless: the page exists to show what a Studio run looks like, and a refusal shows none of it. This ships the recording of one session - mock/sas-transcript.json - and makes the demo's program.sas the program that recording ran, so the source in the editor and the output in the panes are the same run. A visitor sees a log with notes, warnings and two errors, a two-page listing, and a webout with the full ms_webout.sas field set. The recording is the output of a real session with the "Licensed to ..., Site ..." line removed; SYSSITE is 00000000 and the host names are generic, so nothing in it identifies a licensee or a machine. Only the program the recording names is answered: any other .sas program is refused exactly as before, with the message a client already understands. The host answers from data the project ships and invents nothing. The CLI half (sasjs/cli#1575) copies sasjsbuild/sas-transcript.json into the site and answers a run with its three parts; until that release the file travels with the build and is unused.
There was a problem hiding this comment.
Re-review at b9c1c7e. The branch is a single commit again since 457bfbc, so the whole diff is the surface. Both findings from that review are closed: the recording branch is gated on !trigger (sw.js:944) and pinned by keeps a trigger a JSON answer, not the recorded transcript, and the commit body names sas-transcript.json. CI at this head is 11 checks, all green.
- src/commands/build/internal/mockSite/assets/sw.js:954 -
headers: {}- the recording is answered with an empty header set, so a run without_debugreturns the webout with no content-type at all. That is exactly the case the seeded header at runtime-core.js:972 exists to prevent ("so a service that declares no type answers text/html rather than leaving the choice to the browser - a mock build matches that here"), and every other execute answer carries it. Pass the same seed (SEEDED_HEADER_LINE is already in this file) instead of {}, and pin the non-debug answer - both new specs drive_debug=131only, so nothing would notice.
1 finding above for review.
b9c1c7e to
d8283a2
Compare
|
Right: Also right that nothing would have noticed: both new specs drove Mock site specs: 165 tests, 164 pass - the single failure remains the pre-existing Admin-diagnostics test that also fails on clean |
The demo told a visitor that Run on a .sas program needs a server, which was true and useless: the page exists to show what a Studio run looks like, and a refusal shows none of it. This ships the recording of one session - mock/sas-transcript.json - and makes the demo's program.sas the program that recording ran, so the source in the editor and the output in the panes are the same run. A visitor sees a log with notes, warnings and two errors, a two-page listing, and a webout with the full ms_webout.sas field set. The recording is the output of a real session with the "Licensed to ..., Site ..." line removed; SYSSITE is 00000000 and the host names are generic, so nothing in it identifies a licensee or a machine. Only the program the recording names is answered: any other .sas program is refused exactly as before, with the message a client already understands. The host answers from data the project ships and invents nothing. The CLI half (sasjs/cli#1575) copies sasjsbuild/sas-transcript.json into the site and answers a run with its three parts; until that release the file travels with the build and is unused.
There was a problem hiding this comment.
Re-review at d8283a2. The branch is a single commit again, so the whole diff is the surface. The finding from b9c1c7e is closed: the recorded answer carries SEEDED_HEADER_LINE (sw.js:957) and gives a recorded run the seeded content type when not debugging pins the non-debug case.
- src/commands/build/internal/mockSite/assets/sw.js:248 -
Shape: {... "<program path or file name>" ...}- a file name does not match. transcriptFor (:281-290) compareslogicalPath(key)withlogicalPath(request), and logicalPath (:275-278) only strips the/sasjs/drive/filesprefix and the.sassuffix, so a recording keyedprogram.sasis never found for a run of/home/sasjsadmin/program- and the docstring at :270-273 says matching on the file name alone is deliberately not done. Drop "or file name" from the shape, or normalise a bare name to the drive path before comparing.
1 finding above for review.
The demo told a visitor that Run on a .sas program needs a server, which was true and useless: the page exists to show what a Studio run looks like, and a refusal shows none of it. This ships the recording of one session - mock/sas-transcript.json - and makes the demo's program.sas the program that recording ran, so the source in the editor and the output in the panes are the same run. A visitor sees a log with notes, warnings and two errors, a two-page listing, and a webout with the full ms_webout.sas field set. The recording is the output of a real session with the "Licensed to ..., Site ..." line removed; SYSSITE is 00000000 and the host names are generic, so nothing in it identifies a licensee or a machine. Only the program the recording names is answered: any other .sas program is refused exactly as before, with the message a client already understands. The host answers from data the project ships and invents nothing. The CLI half (sasjs/cli#1575) copies sasjsbuild/sas-transcript.json into the site and answers a run with its three parts; until that release the file travels with the build and is unused.
A browser has no SAS binary, so a Run on a .sas program in a mock site is
refused. That refusal is right, but it left the Studio's log, listing and webout
panes with nothing to show - and those panes are the point of the demo.
A project may now ship sas-transcript.json, the recording of one session. The
build copies it into the site and the host answers a program the recording names
with that session's three parts. It is data in the project, not a behaviour of
the host.
- the recording is answered at the route, ahead of the run time check. A
transcript is not a run time: claiming `sas` would make the package compile SAS
source as JavaScript and answer a SyntaxError, and the host would be advertising
an execution mode it does not have. runTimes stays ['js'].
- a .sas program the recording does not name keeps the refusal a client already
understands ('"runTime" must be one of [js]'). The file is resolved first,
because the request may name the program without its extension - without that
check the extensionless path reaches the runner and SAS source is compiled.
- a trigger is not answered from a recording: the trigger route answers with the
session record a client parses as JSON, so the recording applies to runs only.
- matching is on the logical drive path (mount prefix and .sas stripped), so a
recording written as a person sees it answers a request made relative to the
app. It is not a file-name match, which would answer every report.sas in the
drive with a session recorded for another file.
- the debug frame carries the listing after the log - webout SEP log SEP listing -
the split @sasjs/adapter and the Studio already parse; with no listing the frame
closes on the separator as before.
- mockSite.ts: sasjsbuild/sas-transcript.json is carried into the site when the
project has one, and reported as sasTranscript alongside snapshot.
Tests: a recorded program answers with the three parts framed as the adapter
splits them; an unrecorded .sas program still refuses and is not compiled as
JavaScript; a trigger of a recorded program stays a JSON answer; the build ships
the file when present and ships nothing when absent.
d8283a2 to
733ba7e
Compare
|
Right: "or file name" was left over from the basename matching I removed in the previous round, and it contradicted the paragraph a few lines below that explains why a file name is deliberately not enough. A recording keyed Fixed at 733ba7e: the shape now says |
The demo reports runTimes: ['js'], so a .sas program is offered no run time at all: Studio refuses before anything can execute, and the recorded session added in #1575 is only reachable by a client asking for a run time the host says it does not have. sas is now listed. A program the recording names is answered with that session before the run-time check; one it does not name reaches the runner, which refuses it rather than handing SAS source to the JavaScript runtime. The negative case is unchanged and pinned: an unrecorded .sas program answers 400 with the package's refusal, and the test asserts no SyntaxError appears. Mock site specs: 166 tests, 165 pass - the one failure is the pre-existing Admin-diagnostics test that also fails on clean main.
A browser has no SAS binary, so a Run on a
.sasprogram in a mock site is refused. That is the truth and it should stay true - but the Studio's log, listing and webout panes then had nothing real to show, which is the one thing a demo of a Studio run cannot demonstrate.A project may now ship
sasjsbuild/sas-transcript.json, the recording of one real session. The build copies it into the site and the host answers a program the recording names with that session's log, listing and webout. It is data in the project, not a behaviour of the host: a program the recording does not name still reaches the runner and is refused with the package's own message, and no session is invented for a project that ships nothing.What changed
sw.js- the runtime accepts asasrun and answers it from the recording, then flows through the same path as any other run, so a triggered recording is a session the session routes can poll. The debug frame now carries the listing after the log (webout SEP log SEP listing), which is the split@sasjs/adapterand the Studio'sparseExecutionResponsealready handle; with no listing the frame still closes on the separator..sasextension, because the route resolves_programeither way.mockSite.ts-sasjsbuild/sas-transcript.jsonis carried into the site when present and reported assasTranscriptnext tosnapshot.Testing
sw.spec.ts)mockSite.spec.ts)src/commands/build/internal/mockSite/spec: 162 tests, 161 pass. The one failure (answers the Admin reports from the worker activity log) is pre-existing - it fails identically on cleanmain. I left it alone rather than fold an unrelated fix into this change.The companion change in sasjs/server ships the recording itself and points the demo's
program.sasat it.