Skip to content

feat(mock): answer a recorded SAS session - #1575

Merged
allanbowe merged 1 commit into
mainfrom
feat/sas-transcript
Nov 9, 2026
Merged

allanbowe merged 1 commit into
mainfrom
feat/sas-transcript

Conversation

@sasjs-dev

@sasjs-dev sasjs-dev Bot commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

A browser has no SAS binary, so a Run on a .sas program 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 a sas run 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/adapter and the Studio's parseExecutionResponse already handle; with no listing the frame still closes on the separator.
  • matching is by full path or by file name, with or without the .sas extension, because the route resolves _program either way.
  • mockSite.ts - sasjsbuild/sas-transcript.json is carried into the site when present and reported as sasTranscript next to snapshot.

Testing

  • a recorded program answers with the three parts, framed as the adapter splits them (sw.spec.ts)
  • the build ships the recording when the project has one and ships nothing when it does not (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 clean main. 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.sas at it.

@github-actions

github-actions Bot commented Nov 9, 2026 •

Copy link
Copy Markdown

Coverage ratchet

Compared against the baseline published for the base commit cbd3ccb.

Metric Base Head Delta
statements 84.82% 84.87% +0.05 improved
branches 75.27% 75.34% +0.07 improved
functions 83.85% 83.89% +0.04 unchanged
lines 85.37% 85.42% +0.05 unchanged

No metric is below the base.

@sasjs-dev
sasjs-dev Bot force-pushed the feat/sas-transcript branch from 66307db to e336b59 Compare November 9, 2026 15:28

@sasjs-dev sasjs-dev Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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. With runTimes: ['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 to new 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. Keep runTimes: ['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 called report.sas anywhere 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.

@sasjs-dev

sasjs-dev Bot commented Nov 9, 2026

Copy link
Copy Markdown
Contributor Author

Both findings were right, and the first was serious: with runTimes: ['js','sas'] an unrecorded .sas program reached the runner and was compiled as JavaScript - a SyntaxError quoting the SAS source instead of a refusal. Fixed at 457bfbc.

The run time. runTimes is back to ['js'], so the host advertises only what it executes. The recording is now answered at the route, ahead of the run-time check, because a transcript is data rather than a run time. Verified both ways: a recorded program returns its three parts, and an unrecorded .sas program returns 400 with "runTime" must be one of [js] and no SyntaxError in the body.

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 resolveProgram, and the runner uses it to resolve the file before running; if it resolves to .sas, the refusal is thrown. The new negative test pins that.

The match. File-name matching is gone. A recording is matched on the logical drive path - mount prefix and .sas stripped - so a recording written as a person sees it (/sasjs/drive/files/home/sasjsadmin/program.sas) answers a request made relative to the app (/home/sasjsadmin/program), and report.sas in another folder is not answered by a session recorded for a different file. That is also why the demo's fixture still matches, without a basename fallback.

Suite: 163 tests in src/commands/build/internal/mockSite/spec, 162 pass. The single failure (answers the Admin reports from the worker activity log) fails identically on clean main - untouched by this PR. Prettier now covers the asset .js files too, which is what the earlier lint run caught.

@sasjs-dev
sasjs-dev Bot force-pushed the feat/sas-transcript branch from e336b59 to 457bfbc Compare November 9, 2026 15:44
sasjs-dev Bot pushed a commit to sasjs/server that referenced this pull request Nov 9, 2026
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.

@sasjs-dev sasjs-dev Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 200 text/plain body where the route otherwise returns json(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 !trigger so 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 is sas-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.

@sasjs-dev
sasjs-dev Bot force-pushed the feat/sas-transcript branch from 457bfbc to b9c1c7e Compare November 9, 2026 16:04
@sasjs-dev

sasjs-dev Bot commented Nov 9, 2026

Copy link
Copy Markdown
Contributor Author

Both fixed at b9c1c7e.

The trigger. Right, and it would have broken triggerProgram and the Studio: if (!code) swallowed /stp/trigger, so a trigger of a recorded program returned the framed webout as text/plain where the route returns json(answer, 200). Now gated on !code && !trigger, so a trigger keeps the answer it had - the package's refusal for a .sas program, as JSON. Pinned by a test that triggers a recorded program and asserts the content type is JSON and the body has no webout key.

The file name. Also right, and worse than a typo: sasjs-transcript.json is a file nothing reads. The commit body now says sas-transcript.json, matching sw.js, mockSite.ts and sasjs/server's mock/.

On the documentation point: there is no prose docs tree in this repo - docs/ holds only diagrams, and the user-facing CLI documentation is published from elsewhere. So the commit body and this thread are the only documentation here, which is why the filename mattered. If you want it in the published docs, say which repo and I will raise it there rather than inventing a section in this one.

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 main.

sasjs-dev Bot pushed a commit to sasjs/server that referenced this pull request Nov 9, 2026
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.

@sasjs-dev sasjs-dev Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 _debug returns 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=131 only, so nothing would notice.

1 finding above for review.

@sasjs-dev
sasjs-dev Bot force-pushed the feat/sas-transcript branch from b9c1c7e to d8283a2 Compare November 9, 2026 16:29
@sasjs-dev

sasjs-dev Bot commented Nov 9, 2026

Copy link
Copy Markdown
Contributor Author

Right: headers: {} meant a recorded run without _debug answered the webout with no content type at all - the one case the seeded header exists to prevent, and every other execute answer carries it. Fixed at d8283a2 by passing the seed (SEEDED_HEADER_LINE, already in the file) instead of an empty set.

Also right that nothing would have noticed: both new specs drove _debug=131 only. There is now a non-debug case asserting the body is the webout alone and the content type is text/html from the seed.

Mock site specs: 165 tests, 164 pass - the single failure remains the pre-existing Admin-diagnostics test that also fails on clean main.

sasjs-dev Bot pushed a commit to sasjs/server that referenced this pull request Nov 9, 2026
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.

@sasjs-dev sasjs-dev Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) compares logicalPath(key) with logicalPath(request), and logicalPath (:275-278) only strips the /sasjs/drive/files prefix and the .sas suffix, so a recording keyed program.sas is 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.

sasjs-dev Bot pushed a commit to sasjs/server that referenced this pull request Nov 9, 2026
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.
@sasjs-dev
sasjs-dev Bot force-pushed the feat/sas-transcript branch from d8283a2 to 733ba7e Compare November 9, 2026 16:59
@sasjs-dev

sasjs-dev Bot commented Nov 9, 2026

Copy link
Copy Markdown
Contributor Author

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 program.sas would simply never be found.

Fixed at 733ba7e: the shape now says <program path>, and states what the match actually is - the path as written, apart from the /sasjs/drive/files prefix and the .sas suffix - with the reason a bare name is not accepted.

@sasjs-dev sasjs-dev Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the delta at 733ba7e (single commit since d8283a2: the resolveProgram export, the .sas refusal in BrowserRuntime.run, the print part of the debug frame, the shape comment corrected to "", and the three new specs). CI at this head: 11 check runs, all success. No blocking issues found.

@allanbowe
allanbowe merged commit ff558d3 into main Nov 9, 2026
11 checks passed
@allanbowe
allanbowe deleted the feat/sas-transcript branch November 9, 2026 18:23
allanbowe pushed a commit that referenced this pull request Nov 9, 2026
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant