@outerlayer/cli 0.38.0-next.20261106012958 → 0.38.0-next.20261106232046
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +19 -3
- package/dist/agent-setup-IJNDJ4XL.js +40 -0
- package/dist/{agent-subcommand-UNSXJUHA.js → agent-subcommand-XECZFIAS.js} +4 -4
- package/dist/{artifact-link-cmd-QP6VO7AJ.js → artifact-link-cmd-F6M2BDT7.js} +2 -2
- package/dist/{bridge-JI4IO7JN.js → bridge-LDKKFAHH.js} +7 -7
- package/dist/{build-2L3L2OJO.js → build-PTFRHSXI.js} +13 -13
- package/dist/{build-disk-CKBEEF4N.js → build-disk-EO2VG3MF.js} +11 -11
- package/dist/build-info.json +1 -1
- package/dist/{builder-PKDA7X2H.js → builder-LCIBBOWQ.js} +10 -10
- package/dist/caller-Y3RGYXHU.js +23 -0
- package/dist/{check-FG32SYJF.js → check-BNDMAAVS.js} +72 -56
- package/dist/{chunk-T524XQKI.js → chunk-2IVRTP6M.js} +1 -1
- package/dist/{chunk-NEEMG462.js → chunk-2KL345FW.js} +1 -1
- package/dist/{chunk-YXXJBHHF.js → chunk-2VNT47DG.js} +10 -2
- package/dist/{chunk-FGVVBYCT.js → chunk-3HEBSWNE.js} +1 -1
- package/dist/{chunk-RUJR3SDB.js → chunk-3UKDQNFF.js} +1 -1
- package/dist/{chunk-O4Z2YVC3.js → chunk-6AKP3FBS.js} +5 -5
- package/dist/{chunk-VWNQRD4I.js → chunk-6IXZHORY.js} +4 -4
- package/dist/{chunk-VNT2IRLM.js → chunk-6Y4ZE74I.js} +70 -11
- package/dist/{chunk-ONOINHY4.js → chunk-7GQE5D72.js} +1 -1
- package/dist/{chunk-EXIZ3G6I.js → chunk-7VVTZNUP.js} +6 -6
- package/dist/{chunk-DXBYNJRM.js → chunk-B7CAUXSV.js} +6 -6
- package/dist/{chunk-TAEDH2SU.js → chunk-BEQYO2VO.js} +1 -1
- package/dist/{chunk-QWDGHEQL.js → chunk-BJYX3PMU.js} +1 -1
- package/dist/{chunk-CGXYPLK3.js → chunk-BU25W7GF.js} +2 -2
- package/dist/{chunk-X2DX3A7H.js → chunk-C3P637LO.js} +1 -1
- package/dist/{chunk-4MSEUIMK.js → chunk-DDPCKTVN.js} +7 -7
- package/dist/{chunk-EERD7VI3.js → chunk-DRUM7NWK.js} +1 -1
- package/dist/{chunk-GMRVWRHD.js → chunk-EOXQCUFJ.js} +2 -2
- package/dist/{chunk-U7L4GBGS.js → chunk-FPPBL7ZC.js} +1 -1
- package/dist/{chunk-EFAOERZH.js → chunk-FSQDS7A6.js} +1 -1
- package/dist/{chunk-YWWW47OY.js → chunk-FSYEDSSA.js} +1 -1
- package/dist/{chunk-3FAJMXBA.js → chunk-FZD6GIW5.js} +9 -9
- package/dist/{chunk-KLQLQQGG.js → chunk-GMLYSAKU.js} +3 -3
- package/dist/{chunk-ABN4UBR5.js → chunk-HCIOUSUX.js} +2 -3
- package/dist/{chunk-QONY6C2B.js → chunk-HI5FSBWD.js} +15 -9
- package/dist/{chunk-3XWZKL2P.js → chunk-ICKFR2DB.js} +7 -7
- package/dist/{chunk-JTDMSQMI.js → chunk-IQHREL5T.js} +8 -8
- package/dist/{chunk-FOUG2R4Q.js → chunk-LPTMKPCD.js} +1 -1
- package/dist/{chunk-HG2ZG6ZU.js → chunk-LQEI4HZF.js} +1 -1
- package/dist/{chunk-ZTJTAKVW.js → chunk-LYBHKNEG.js} +1 -1
- package/dist/{chunk-5VAXNAOD.js → chunk-LYORNXIT.js} +1 -1
- package/dist/{chunk-OVHBDADU.js → chunk-MLM4BYK2.js} +1 -1
- package/dist/{chunk-RSRNZB4T.js → chunk-MXSQINKG.js} +7 -7
- package/dist/{chunk-L4ACBB5R.js → chunk-NDLWXIVK.js} +1 -1
- package/dist/{chunk-S7CE7QCF.js → chunk-NMSWL2N3.js} +3 -3
- package/dist/{chunk-XDRZ3BNA.js → chunk-NOBB3LEO.js} +1 -1
- package/dist/{chunk-256R6O56.js → chunk-O3TOA2KE.js} +8 -5
- package/dist/{chunk-YZRDJOOR.js → chunk-OAOZDJYT.js} +3 -3
- package/dist/{chunk-IXB2IIEW.js → chunk-OCQ5FQZR.js} +1 -1
- package/dist/{chunk-AVEF3T6Y.js → chunk-OO33S4AF.js} +7 -5
- package/dist/{chunk-BO3NOGKE.js → chunk-OSHKKESX.js} +77 -8
- package/dist/{chunk-RZ6WJTUP.js → chunk-PJNOTSB5.js} +1 -1
- package/dist/{chunk-ZLJXMXZP.js → chunk-PVLDVUNJ.js} +2 -2
- package/dist/{chunk-MPE4NOKD.js → chunk-QF6US5YN.js} +2 -2
- package/dist/{chunk-OUHM6U6Z.js → chunk-QHT6PIFP.js} +144 -5
- package/dist/{chunk-45TFVWNT.js → chunk-QQSXVGVH.js} +6 -6
- package/dist/{chunk-DVFGCVTV.js → chunk-QZAZPRDW.js} +5 -5
- package/dist/{chunk-XE2PXGZT.js → chunk-RWNVQSGX.js} +3 -3
- package/dist/{chunk-EHJYXABQ.js → chunk-RZXP427Z.js} +1 -1
- package/dist/{chunk-OGQW7A4G.js → chunk-S35KTDTM.js} +10 -10
- package/dist/{chunk-3DVCPRKE.js → chunk-SDUCKX46.js} +9 -9
- package/dist/{chunk-CCMKLF7K.js → chunk-SEAVWMW2.js} +6 -6
- package/dist/{chunk-BL6CCU26.js → chunk-SOB4KVRZ.js} +6 -6
- package/dist/{chunk-U5EE7PGC.js → chunk-SYENSVOK.js} +3 -3
- package/dist/{chunk-2MQQASWB.js → chunk-SZQKS4QK.js} +6 -6
- package/dist/{chunk-ERQLHUWU.js → chunk-TWWAV67F.js} +5 -5
- package/dist/{chunk-Z4R36YDJ.js → chunk-V26DDAWZ.js} +1367 -548
- package/dist/{chunk-OFWNBTLU.js → chunk-V43NFQE3.js} +1 -1
- package/dist/{chunk-WF2NXBOM.js → chunk-VLAVNWM4.js} +7 -7
- package/dist/{chunk-SMFWLPXC.js → chunk-VW5NG2AR.js} +19 -18
- package/dist/{chunk-PARDL7HH.js → chunk-VYAFSV43.js} +1 -1
- package/dist/{chunk-DL5N6V3D.js → chunk-VZGTPITG.js} +1 -1
- package/dist/{chunk-AJC5Q2NY.js → chunk-WCBLLIPD.js} +5 -5
- package/dist/{chunk-AMG5ICDO.js → chunk-WCQJNDQC.js} +4 -4
- package/dist/{chunk-YKWOVYVN.js → chunk-WDJPGE6K.js} +9 -6
- package/dist/{chunk-MDKLSY43.js → chunk-WX7XACEU.js} +1 -1
- package/dist/{chunk-5R5FEPLH.js → chunk-X25VXXCF.js} +99 -18
- package/dist/{chunk-ZO3RUMUR.js → chunk-X32HZMMA.js} +4 -4
- package/dist/{chunk-K6JOU4CT.js → chunk-XDURUWQP.js} +156 -51
- package/dist/{chunk-FER7JJ3S.js → chunk-XKJZHY4J.js} +1 -1
- package/dist/{chunk-PMJ6IEUM.js → chunk-XSEAGCYW.js} +7 -7
- package/dist/{chunk-ZCEM4GJ5.js → chunk-YFARFA4Y.js} +3 -3
- package/dist/{chunk-DK5YFDYI.js → chunk-YSCRMX2T.js} +8 -8
- package/dist/{claude-launcher-FHQTSQOM.js → claude-launcher-62NZAUKT.js} +7 -7
- package/dist/{cli-GNC4MFMP.js → cli-GJQGNNFM.js} +161 -154
- package/dist/{command-47EYM2FJ.js → command-3QXN5ZTK.js} +59 -52
- package/dist/config-4YPIDOHH.js +22 -0
- package/dist/{connect-cmd-4JO2LBUT.js → connect-cmd-GAWR7QSH.js} +13 -13
- package/dist/{container-start-XR7KANS6.js → container-start-FZCTPBZG.js} +48 -48
- package/dist/{context-cleanup-6CTKLEUT.js → context-cleanup-L3ZKG6EU.js} +4 -4
- package/dist/{context-show-cmd-Z7NQAKNE.js → context-show-cmd-YJ4IJ2WI.js} +14 -14
- package/dist/{control-plane-launch-4PLBJKBS.js → control-plane-launch-GOKEVTPX.js} +14 -14
- package/dist/{demo-record-cmd-3B2ME2ZI.js → demo-record-cmd-AZSEQXO4.js} +8 -8
- package/dist/{demo-voice-cmd-LIXAA3OS.js → demo-voice-cmd-KHEMTR5T.js} +20 -20
- package/dist/{dist-3TV6G4YF.js → dist-RMEOTTVL.js} +2 -2
- package/dist/{docker-FPEQS6HK.js → docker-QMKIWXHF.js} +10 -10
- package/dist/{doctor-AFH6UUX6.js → doctor-5PTO2DN7.js} +56 -50
- package/dist/{emit-artifact-cmd-5XIEUWFX.js → emit-artifact-cmd-72QEOEJH.js} +19 -19
- package/dist/{emit-cmd-IKYF27IK.js → emit-cmd-X5F5HUTQ.js} +7 -7
- package/dist/{emit-criteria-cmd-YS5ZSLCN.js → emit-criteria-cmd-HTHETRH6.js} +16 -16
- package/dist/{emit-demo-cmd-IDC2JC46.js → emit-demo-cmd-LFYJURFC.js} +20 -20
- package/dist/{emit-finding-cmd-C4NRTIZO.js → emit-finding-cmd-GFWCMJFY.js} +16 -16
- package/dist/{emit-result-cmd-GC2I7JQU.js → emit-result-cmd-FTWLKM6G.js} +18 -18
- package/dist/{emit-step-cmd-TTH4FYFW.js → emit-step-cmd-J4L2OAWE.js} +16 -16
- package/dist/{exec-client-DT5EWVQL.js → exec-client-YQH4ZSRM.js} +8 -8
- package/dist/find-unit-F3Q54LLR.js +24 -0
- package/dist/{findings-cmd-MSV52ODM.js → findings-cmd-VFE7VINC.js} +16 -16
- package/dist/{fleet-readiness-O76CSI7M.js → fleet-readiness-FGQPCFSP.js} +14 -14
- package/dist/{governing-source-QEFYVBQF.js → governing-source-NMZSHEHR.js} +21 -21
- package/dist/{guest-init-X7M5AIOI.js → guest-init-DPZAVCWH.js} +9 -9
- package/dist/{hook-fast-T6FOTZHA.js → hook-fast-3VMKCCUO.js} +1 -1
- package/dist/{hook-install-OUSUHQ6C.js → hook-install-TTF6LASI.js} +4 -4
- package/dist/host-checks-ANVIJJZI.js +79 -0
- package/dist/host-key-QZWN6ECO.js +18 -0
- package/dist/{image-tag-AE6EKDPV.js → image-tag-5TZ7MF5H.js} +8 -8
- package/dist/index.js +4 -4
- package/dist/{init-PUN3PKOT.js → init-5ZTKM5KM.js} +46 -46
- package/dist/init-6AAXECDJ.js +79 -0
- package/dist/{init-agent-D3KK24QX.js → init-agent-FOR3XGZ2.js} +46 -46
- package/dist/{init-cmd-LGRN3U7K.js → init-cmd-7X22EFRG.js} +27 -27
- package/dist/{init-update-ZL2J7EQI.js → init-update-JLOPXC5U.js} +24 -24
- package/dist/{install-cmd-4ID4VBH2.js → install-cmd-JDA4CNYW.js} +10 -10
- package/dist/{layout-G6K72TXK.js → layout-AKKICGLZ.js} +4 -4
- package/dist/{login-browser-I6CWBA7K.js → login-browser-VNPN4FVO.js} +2 -2
- package/dist/{logs-DIA3NWC2.js → logs-WPNNAY5E.js} +7 -7
- package/dist/loop-DFDQQC2Q.js +90 -0
- package/dist/machine-W3R5I6EM.js +79 -0
- package/dist/{machine-skills-JLJJDXBS.js → machine-skills-GGLBQANZ.js} +4 -4
- package/dist/{mcp-install-cmd-OTAX7QP2.js → mcp-install-cmd-3NHDPAML.js} +4 -4
- package/dist/{mcp-serve-cmd-63KQEQYS.js → mcp-serve-cmd-CLVZFL37.js} +9 -9
- package/dist/{paths-KVMMJQ7T.js → paths-PSLRVOVY.js} +7 -7
- package/dist/pending-GWDAXQSA.js +18 -0
- package/dist/{pidfile-NCBBWZNH.js → pidfile-5E4YPCTC.js} +8 -8
- package/dist/{record-PQDJVKYV.js → record-7ZMZA5QE.js} +8 -8
- package/dist/relay-UUIHK5TY.js +474 -0
- package/dist/{relay-protocol-PJ2HOP6B.js → relay-protocol-MQVXSFN4.js} +5 -5
- package/dist/{runner-agents-CEW4Z3FR.js → runner-agents-M5CMF2ZA.js} +4 -4
- package/dist/runner-env-3S64BNCU.js +24 -0
- package/dist/{runner-identity-IJKE4SRJ.js → runner-identity-3GMF6FKI.js} +10 -10
- package/dist/{runner-key-4J4MHN3S.js → runner-key-NS5C5TTT.js} +46 -46
- package/dist/{session-sender-HKNACIH5.js → session-sender-M325MH5U.js} +19 -19
- package/dist/{spec-cmd-4R7AYTBU.js → spec-cmd-QIVFOHR4.js} +17 -17
- package/dist/{starter-pack-6C7HPT4O.js → starter-pack-P5BRWSAP.js} +5 -5
- package/dist/state-5H5LGYWN.js +18 -0
- package/dist/{status-GMVC666R.js → status-5YK3LOVJ.js} +46 -46
- package/dist/{sync-cmd-UMAENSGZ.js → sync-cmd-JHFRUMM5.js} +18 -18
- package/dist/update-steps-KFULBARX.js +80 -0
- package/dist/{watch-RAUF223H.js → watch-TVHFOLVK.js} +18 -18
- package/dist/{work-claim-cmd-A3ISXUFA.js → work-claim-cmd-LTIAXIWH.js} +23 -23
- package/dist/{work-cmd-U7YLMDZ7.js → work-cmd-VC353JLU.js} +16 -16
- package/dist/{work-comment-cmd-CMWMOWVG.js → work-comment-cmd-SRQXRRJT.js} +18 -18
- package/dist/{work-demo-cmd-EKTJHIVM.js → work-demo-cmd-INUFIHU4.js} +16 -16
- package/dist/{work-logs-cmd-Z3QOFYTJ.js → work-logs-cmd-TMJC7RRS.js} +16 -16
- package/dist/{work-open-pr-cmd-NJXIX3QZ.js → work-open-pr-cmd-O6XW2YGD.js} +17 -17
- package/dist/{work-pr-cmd-JUV3SN7I.js → work-pr-cmd-QSE3BH3Z.js} +16 -16
- package/dist/{work-proofs-cmd-MIDPIFTH.js → work-proofs-cmd-FXSVPQZC.js} +18 -18
- package/dist/{work-proofs-record-6FTMJDQG.js → work-proofs-record-KPRP3UAQ.js} +24 -24
- package/dist/{work-stop-cmd-Z7MYNR7R.js → work-stop-cmd-J77H7RLL.js} +16 -16
- package/package.json +1 -1
- package/skill-pack/maintained/outerlayer-build/SKILL.md +6 -7
- package/skill-pack/maintained/outerlayer-build/references/code-review-judge.md +80 -0
- package/skill-pack/maintained/outerlayer-build/references/release.md +0 -15
- package/skill-pack/maintained/outerlayer-build/references/review-loop.md +1 -3
- package/skill-pack/maintained/outerlayer-evidence/SKILL.md +3 -7
- package/dist/agent-setup-CBEPGNFY.js +0 -40
- package/dist/caller-XETCC46J.js +0 -23
- package/dist/config-EA6WVKAS.js +0 -22
- package/dist/find-unit-337Y4QAC.js +0 -24
- package/dist/host-checks-OXB5J3KR.js +0 -79
- package/dist/host-key-UFUIBFBF.js +0 -18
- package/dist/init-V7X3KA7B.js +0 -79
- package/dist/loop-AWBFKDV7.js +0 -90
- package/dist/machine-BZPKYURG.js +0 -79
- package/dist/pending-2IE3VBAN.js +0 -18
- package/dist/relay-QDB526DJ.js +0 -223
- package/dist/runner-env-23OLQBQZ.js +0 -24
- package/dist/state-DPEWDXQN.js +0 -18
- package/dist/update-steps-GTXNCG3Z.js +0 -80
- package/skill-pack/validators/code-review.yaml +0 -30
|
@@ -1,60 +1,60 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { createRequire } from 'node:module';
|
|
3
|
-
import { itemsSentence, criteriaOf, hostItemsOf, loadCitationFinder, testFileMatcher, planCriteria, judgeGroups, failedItems, inCriteriaOrder, testsByCriterion, oneLineReason, criterionInputs, parseJudgeAnswer, judgedItems, MAX_TEST_FILE_BYTES } from './chunk-
|
|
3
|
+
import { itemsSentence, criteriaOf, hostItemsOf, loadCitationFinder, testFileMatcher, planCriteria, wholeItems, judgeGroups, failedItems, inCriteriaOrder, testsByCriterion, oneLineReason, criterionInputs, parseJudgeAnswer, judgedItems, openPullRequests, MAX_TEST_FILE_BYTES } from './chunk-OSHKKESX.js';
|
|
4
4
|
import { sha256OfFile, downloadPinned, VoiceDownloadError } from './chunk-2PGI6RDE.js';
|
|
5
5
|
import { zodProblem } from './chunk-I3LTIAOR.js';
|
|
6
|
-
import { hasStoredCredential, storedCredentialVariables, storeAgentCredential, isAgentName, credentialFromStdin } from './chunk-
|
|
7
|
-
import { upgradedStarterText } from './chunk-
|
|
8
|
-
import { HELPER_PATH, HELPER_RECORD, DOCKERD_LOG } from './chunk-
|
|
9
|
-
import { writeDockerClientConfig } from './chunk-
|
|
10
|
-
import { senderPidfile } from './chunk-
|
|
11
|
-
import { installScrubContext } from './chunk-
|
|
6
|
+
import { hasStoredCredential, storedCredentialVariables, storeAgentCredential, isAgentName, credentialFromStdin } from './chunk-WCBLLIPD.js';
|
|
7
|
+
import { upgradedStarterText } from './chunk-TWWAV67F.js';
|
|
8
|
+
import { HELPER_PATH, HELPER_RECORD, DOCKERD_LOG } from './chunk-OAOZDJYT.js';
|
|
9
|
+
import { writeDockerClientConfig } from './chunk-7GQE5D72.js';
|
|
10
|
+
import { senderPidfile } from './chunk-6IXZHORY.js';
|
|
11
|
+
import { installScrubContext } from './chunk-SDUCKX46.js';
|
|
12
12
|
import { readsJobState, READ_JOB_STATE_FORMATS, jobStateFormatOf } from './chunk-ZVB57WI6.js';
|
|
13
|
-
import { runnerImageVersion } from './chunk-
|
|
14
|
-
import { claimCalls, spoolHomeFor, itemCalls, claimItem, leftByRunnerKey } from './chunk-
|
|
13
|
+
import { runnerImageVersion } from './chunk-BEQYO2VO.js';
|
|
14
|
+
import { claimCalls, spoolHomeFor, itemCalls, claimItem, leftByRunnerKey } from './chunk-PVLDVUNJ.js';
|
|
15
15
|
import { receiveFiles } from './chunk-NN33FYXG.js';
|
|
16
|
-
import { readDefaultBranchFiles, readDefaultBranchHead, buildRepositoryImage, fetchCommit, readBranchHead, diffBetween, prepareImageBuild, KEY_PREFIX, TAG_HOST, SHARED_OWNER, SHARED_NAME, universalBase, metadataFromLabels, writeRecord } from './chunk-
|
|
17
|
-
import { FETCHED_DIR, toolsDockerfile, FETCHED_FFMPEG, FETCHED_GH, FETCHED_TINI, FETCHED_HEADLESS_SHELL, FETCHED_PLAYWRIGHT_FFMPEG, FETCHED_VOICE_DIR } from './chunk-
|
|
16
|
+
import { readDefaultBranchFiles, readDefaultBranchHead, buildRepositoryImage, fetchCommit, readBranchHead, diffBetween, prepareImageBuild, KEY_PREFIX, TAG_HOST, SHARED_OWNER, SHARED_NAME, universalBase, metadataFromLabels, writeRecord } from './chunk-VLAVNWM4.js';
|
|
17
|
+
import { FETCHED_DIR, toolsDockerfile, FETCHED_FFMPEG, FETCHED_GH, FETCHED_TINI, FETCHED_HEADLESS_SHELL, FETCHED_PLAYWRIGHT_FFMPEG, FETCHED_VOICE_DIR } from './chunk-WDJPGE6K.js';
|
|
18
18
|
import { isSameProcess, startTimeOf } from './chunk-JBJTC3UU.js';
|
|
19
19
|
import { currentCliBuild } from './chunk-OGFGZQA3.js';
|
|
20
|
-
import { vmExecArgs, runExec, execCapture, waitForAgent } from './chunk-
|
|
21
|
-
import { socketPathProblem, vsockLinks, linkVsockSockets, GUEST_CID, LEASE_LINK } from './chunk-
|
|
22
|
-
import { describeCallFailure, shortClaim, retrySend, commandWithShim, logStamp, createRunnerLog, formatDuration, removeKeptContext, formatClock, stageGovernedContext, keptContextTree, removeStagedContext,
|
|
23
|
-
import { postJson, WorkCommandError, getJson, isSignatureRefusal } from './chunk-
|
|
24
|
-
import { runnerCredentialProblem, builtinKind, keyRunnerFactory, optionalEgress, isBuiltinContainer, isBuiltinVm, egressSummary, DEFAULT_WORKSPACE_KEEP_DAYS, DEFAULT_CHECK_TIME_LIMIT_MINUTES,
|
|
25
|
-
import { formatBytes, volumeBytes, allocatedBytes, DEFAULT_BUILD_DISK, DEFAULT_CACHE_DISK, freeBytes } from './chunk-
|
|
26
|
-
import {
|
|
27
|
-
import { universalImagePending, RecipeError, writeSanitizedRecipe, classifyProperties, DOCKER_FEATURE } from './chunk-
|
|
28
|
-
import { sanitizeTerminal, planArtifactUpload } from './chunk-
|
|
29
|
-
import { sharedSkillNames, skillConflictMessage } from './chunk-
|
|
20
|
+
import { vmExecArgs, runExec, execCapture, waitForAgent } from './chunk-LQEI4HZF.js';
|
|
21
|
+
import { socketPathProblem, vsockLinks, linkVsockSockets, GUEST_CID, LEASE_LINK } from './chunk-SYENSVOK.js';
|
|
22
|
+
import { describeCallFailure, shortClaim, retrySend, resolveGoverningSource, prefetchGovernedContext, refusalCode, commandWithShim, logStamp, createRunnerLog, formatDuration, removeKeptContext, formatClock, stageGovernedContext, keptContextTree, removeStagedContext, keepStagedContext, pinnedSourceOf, WORKFLOW_PERMISSION_REASON, shimScript, controlPlaneTokenFailure } from './chunk-ICKFR2DB.js';
|
|
23
|
+
import { postJson, WorkCommandError, getJson, isSignatureRefusal } from './chunk-IQHREL5T.js';
|
|
24
|
+
import { runnerCredentialProblem, builtinKind, keyRunnerFactory, sandboxSizeOf, networkOf, sandboxTimeLimitMinutes, DEFAULT_SETUP_MINUTES, optionalEgress, isBuiltinContainer, isBuiltinVm, isBuiltinSandbox, egressSummary, DEFAULT_WORKSPACE_KEEP_DAYS, DEFAULT_CHECK_TIME_LIMIT_MINUTES, allowHostProblem, systemClock, emptyEgressCounts, hostAllowed, imageBuildOf, DEFAULT_SAVED_STATE_MAX_BYTES } from './chunk-6Y4ZE74I.js';
|
|
25
|
+
import { formatBytes, volumeBytes, allocatedBytes, DEFAULT_BUILD_DISK, DEFAULT_CACHE_DISK, freeBytes } from './chunk-QF6US5YN.js';
|
|
26
|
+
import { runnerLabelValue, said, RUNNER_LABEL, BUILD_LABEL, prepareRunArgs, containerRunArgs, firstLine, writeJobFile, readJobFile, spawnRun, NETWORK_HELPER_MEMORY, createDockerHost, builderSpec, mountableHome, homeCopyRunArgs, containerExecArgs, childEnvironment, readDu, identityRunArgs, parseIdentity, withAnswerProtocol, JUDGE_TREE, MAX_REPORT_BYTES, parseSize, readJobFileChecked, NETWORK_READY_FILE, networkHelperName, judgeCommand, WORKSPACE_LABEL, networkHelperRunArgs, JUDGE_MAX_TURNS, JUDGE_DIR, hashJudgeProgram, identityScript, identityArgs, homeCopyScript, homeCopyArgs, COMMAND_DIR, judgeProgramRecord, MAX_ITEMS_BYTES, JUDGE_ITEMS, JUDGE_REPORT, SAVED_STATE_LABEL } from './chunk-FZD6GIW5.js';
|
|
27
|
+
import { universalImagePending, RecipeError, writeSanitizedRecipe, classifyProperties, DOCKER_FEATURE } from './chunk-XKJZHY4J.js';
|
|
28
|
+
import { sanitizeTerminal, planArtifactUpload } from './chunk-OCQ5FQZR.js';
|
|
29
|
+
import { sharedSkillNames, skillConflictMessage } from './chunk-BJYX3PMU.js';
|
|
30
30
|
import { readCloudConfig } from './chunk-HWVMRETT.js';
|
|
31
|
-
import { signerFor } from './chunk-
|
|
32
|
-
import { vmAssetsDir, RUNNER_DIR_MODE, RUNNER_FILE_MODE, runnerDir, workspacesDir, jobsDir, storeScopes, spoolDir, orgStoreIn, rootfsDir, imagesDir, sessionsDir, builderCacheDiskPath, buildsDir,
|
|
33
|
-
import { BUILD_HOME, JOB_MOUNT, heldBuildAuthority, IMAGE_BUNDLES, writeTrustFiles,
|
|
34
|
-
import { agentCredential, RUNNER_WORDED_REASONS, UNKNOWN_TRACKING_REASON, UNKNOWN_TRANSPORT_REASON, RELAY_USER,
|
|
31
|
+
import { signerFor } from './chunk-FSQDS7A6.js';
|
|
32
|
+
import { vmAssetsDir, RUNNER_DIR_MODE, RUNNER_FILE_MODE, runnerDir, buildDir, ghConfigDir, workspacesDir, jobsDir, storeScopes, spoolDir, orgStoreIn, rootfsDir, imagesDir, sessionsDir, builderCacheDiskPath, buildsDir, runnerDirOfBuild, mirrorDir, orgHomeDir, deliveryDir, jobConsolePath, vsockPath, SHIM_DIR, builderConsolePath, rootfsPathFor, diskTemplatesDir } from './chunk-LYORNXIT.js';
|
|
33
|
+
import { BUILD_HOME, repositoriesOf, primaryOf, SandboxError, describeSandboxError, buildEnvironment, CHECKOUT_DIR, JOB_MOUNT, heldBuildAuthority, IMAGE_BUNDLES, writeTrustFiles, trustEnvironment, parseIsolation, containerLocalAddress, destinationEnvironment, withHooksPath, startBuildServices, headerVariables, authorEnvironment, sharedUserEnvironment, withTunnelRecord, commitIdentityRecord, RELAY_PORT, repositoryPath, lifecycleWorkdir, CHECK_ITEMS_FILE, parseProxied, toolProxyEnvironment, readBundleScript, applyTrust, STAND_IN, proxyEnvironment, dropBuildAuthority, sandboxSettingsFrom, createSandboxClient, hostKeyOf, buildAuthorityFor, checkEnvironment, withMiseVariables, checkoutPath, variablesFor, carried6to4, classifyAddress, EVAL_INPUT_DIR, isMiseVariableAllowed, variableForPath, droppedRequestHeaders, hasDotDotSegment, routeNameOf } from './chunk-QHT6PIFP.js';
|
|
34
|
+
import { agentCredential, builtInNames, RUNNER_WORDED_REASONS, UNKNOWN_TRACKING_REASON, UNKNOWN_TRANSPORT_REASON, RELAY_USER, MAX_MALFORMED_SESSIONS, MALFORMED_REASON, JOIN_WAIT_MS, currentAgentCredential, removedAgentCredentialValues, managedAgentCredential, realFdStorePort, RELAY_ID, MAX_OPEN_STREAMS, STREAM_RESET_RATE, STREAM_RESET_BURST, STREAM_WINDOW, SESSION_WINDOW, targetOfPath, AGENT_CREDENTIAL_MISSING, fdName, DOCKER_DESKTOP_REASON } from './chunk-BU25W7GF.js';
|
|
35
35
|
import { versionAtLeast } from './chunk-SF2TBJBP.js';
|
|
36
|
-
import { jobAgent, firecrackerArch, MICROVM_ARCHES, FIRECRACKER_VERSION, hostHelperPinned, builderDiskPinned, guestAssetsPinned, runnerAgentNamed, credentialForms, orList, credentialShapes, agentCommands, defaultCommandLine, credentialAgent, GUEST_HELPER_SHA256, GUEST_ASSETS_BASE_URL, GUEST_KERNEL_SHA256, JAILER_BINARY_SHA256, FIRECRACKER_BINARY_SHA256, FIRECRACKER_SHA256, GUEST_ASSETS_VERSION, BUILDER_DISK_VERSION, credentialHandOffKey, strippedVariables, runnerAgents, judgeAgent, networkHelperPinned, NETWORK_HELPER_SHA256, universalImagePinned, UNIVERSAL_IMAGE, FFMPEG_STATIC, FFMPEG_BUILD_TAG, GH_SHA256, GH_VERSION, TINI_SHA256, TINI_VERSION, HEADLESS_SHELL, HEADLESS_SHELL_BASE_URL, PLAYWRIGHT_FFMPEG, PLAYWRIGHT_FFMPEG_BASE_URL, VOICE_PACK_FILES, BUILDER_DISK_SHA256, BUILDER_DISK_BASE_URL, DEFAULT_BASE_IMAGE
|
|
37
|
-
import { sessionFolderIn, legacyAgent, defaultAgents, parsePolicy, AGENTS_SKILLS_BASE, OUTERLAYER_SKILLS_BASE, orderSessions, extractFacts, sessionsToTimeline, resolvePackRoot } from './chunk-
|
|
36
|
+
import { jobAgent, firecrackerArch, MICROVM_ARCHES, FIRECRACKER_VERSION, hostHelperPinned, builderDiskPinned, guestAssetsPinned, runnerAgentNamed, credentialForms, orList, credentialShapes, agentCommands, defaultCommandLine, credentialAgent, agentVersionOf, GUEST_HELPER_SHA256, GUEST_ASSETS_BASE_URL, GUEST_KERNEL_SHA256, JAILER_BINARY_SHA256, FIRECRACKER_BINARY_SHA256, FIRECRACKER_SHA256, GUEST_ASSETS_VERSION, BUILDER_DISK_VERSION, credentialHandOffKey, strippedVariables, runnerAgents, judgeAgent, networkHelperPinned, NETWORK_HELPER_SHA256, universalImagePinned, UNIVERSAL_IMAGE, FFMPEG_STATIC, FFMPEG_BUILD_TAG, GH_SHA256, GH_VERSION, TINI_SHA256, TINI_VERSION, HEADLESS_SHELL, HEADLESS_SHELL_BASE_URL, PLAYWRIGHT_FFMPEG, PLAYWRIGHT_FFMPEG_BASE_URL, VOICE_PACK_FILES, BUILDER_DISK_SHA256, BUILDER_DISK_BASE_URL, DEFAULT_BASE_IMAGE } from './chunk-PJNOTSB5.js';
|
|
37
|
+
import { sessionFolderIn, legacyAgent, defaultAgents, parsePolicy, AGENTS_SKILLS_BASE, OUTERLAYER_SKILLS_BASE, orderSessions, extractFacts, sessionsToTimeline, resolvePackRoot } from './chunk-OO33S4AF.js';
|
|
38
38
|
import { MAINTAINED_SKILLS } from './chunk-CDDED64E.js';
|
|
39
39
|
import { resolveVersion } from './chunk-RA3O54FC.js';
|
|
40
40
|
import { homeFromEnv } from './chunk-352DHUTP.js';
|
|
41
|
-
import { scrubText, MIN_SCRUBBED_LITERAL, setCustomScrubbers, setLocalIdentity, setRepoRoot, forkFor, scrubDeep } from './chunk-
|
|
42
|
-
import { CheckItemsSchema, CHECK_ITEM_HREF_MAX_LENGTH, downconvertSession } from './chunk-
|
|
41
|
+
import { scrubText, MIN_SCRUBBED_LITERAL, setCustomScrubbers, setLocalIdentity, setRepoRoot, forkFor, scrubDeep } from './chunk-X25VXXCF.js';
|
|
42
|
+
import { CheckItemsSchema, CODE_REVIEW_NAME, JUDGE_NOT_RUN_ITEM_ID, REVIEWED_COMMIT_ITEM_ID, CHECK_ITEM_REASON_MAX_LENGTH, CHECK_ITEM_HREF_MAX_LENGTH, downconvertSession } from './chunk-2VNT47DG.js';
|
|
43
43
|
import { randomUUID, randomBytes, createHash } from 'crypto';
|
|
44
|
-
import { rmSync, mkdirSync, existsSync, readFileSync, mkdtempSync, statSync, appendFileSync, writeFileSync, readdirSync, accessSync, constants, openSync, closeSync, renameSync, rmdirSync, createReadStream, lstatSync, unlinkSync,
|
|
44
|
+
import { rmSync, mkdirSync, existsSync, readFileSync, mkdtempSync, statSync, appendFileSync, writeFileSync, readdirSync, accessSync, constants, openSync, closeSync, renameSync, rmdirSync, chmodSync, createReadStream, lstatSync, unlinkSync, realpathSync, writeSync, truncateSync, cpSync, fstatSync, readSync, createWriteStream, copyFileSync, linkSync } from 'fs';
|
|
45
45
|
import { join, dirname, isAbsolute, delimiter, basename, sep, relative, resolve } from 'path';
|
|
46
|
-
import {
|
|
46
|
+
import { PassThrough, Writable, Duplex, Readable, Transform } from 'stream';
|
|
47
47
|
import { spawn, spawnSync } from 'child_process';
|
|
48
48
|
import { createServer, createConnection, connect, isIP } from 'net';
|
|
49
49
|
import { availableParallelism, networkInterfaces, tmpdir } from 'os';
|
|
50
|
+
import { gzipSync, createGunzip, gunzipSync, constants as constants$1 } from 'zlib';
|
|
51
|
+
import http2 from 'http2';
|
|
50
52
|
import { once } from 'events';
|
|
51
53
|
import { createServer as createServer$1, request, Agent } from 'http';
|
|
52
54
|
import { lookup as lookup$1 } from 'dns/promises';
|
|
53
55
|
import { TLSSocket, createSecureContext, connect as connect$1 } from 'tls';
|
|
54
|
-
import http2 from 'http2';
|
|
55
56
|
import { request as request$1 } from 'https';
|
|
56
57
|
import { pipeline, finished } from 'stream/promises';
|
|
57
|
-
import { createGunzip, gunzipSync, constants as constants$1 } from 'zlib';
|
|
58
58
|
|
|
59
59
|
createRequire(import.meta.url);
|
|
60
60
|
|
|
@@ -335,6 +335,23 @@ async function restoreSession(input) {
|
|
|
335
335
|
return { ok: false, reason: describeCallFailure(err) };
|
|
336
336
|
}
|
|
337
337
|
}
|
|
338
|
+
var NAMES_A_FAILURE = /\b(error|failed|fatal|denied|refused|cannot|could not|unable|not found|timed out|timeout)\b/i;
|
|
339
|
+
function failedStepLine(log) {
|
|
340
|
+
const lines = log.split(/\r?\n/);
|
|
341
|
+
const end = lines.findLastIndex((line2) => /^#\d+ ERROR: /.test(line2));
|
|
342
|
+
if (end === -1) return void 0;
|
|
343
|
+
const step = /^#(\d+) /.exec(lines[end])[1];
|
|
344
|
+
const prefix = new RegExp(`^#${step} \\d+(?:\\.\\d+)? (.*)$`);
|
|
345
|
+
const output = lines.map((line2) => (prefix.exec(line2)?.[1] ?? "").trim()).filter((line2) => line2 !== "");
|
|
346
|
+
return output.filter((line2) => !line2.startsWith("at ") && NAMES_A_FAILURE.test(line2)).at(-1) ?? output.at(-1);
|
|
347
|
+
}
|
|
348
|
+
function failedStepLineOf(path) {
|
|
349
|
+
try {
|
|
350
|
+
return failedStepLine(readFileSync(path ?? "", "utf8"));
|
|
351
|
+
} catch {
|
|
352
|
+
return void 0;
|
|
353
|
+
}
|
|
354
|
+
}
|
|
338
355
|
|
|
339
356
|
// src/runner/managed-claude-key.ts
|
|
340
357
|
var FETCH_RETRY_WINDOW_MS = 3e4;
|
|
@@ -1395,6 +1412,25 @@ function createMicroVmPorts(over = {}) {
|
|
|
1395
1412
|
};
|
|
1396
1413
|
}
|
|
1397
1414
|
|
|
1415
|
+
// src/runner/sandbox/ports.ts
|
|
1416
|
+
function createSandboxPorts(opts, hostEnv) {
|
|
1417
|
+
let made;
|
|
1418
|
+
return {
|
|
1419
|
+
client: opts?.client ?? (() => {
|
|
1420
|
+
if (made !== void 0) return made;
|
|
1421
|
+
const found = sandboxSettingsFrom(hostEnv);
|
|
1422
|
+
if (!found.ok) throw new SandboxError(`${found.missing.join(", ")} not set in the runner's environment`, 0, "no_api_key");
|
|
1423
|
+
made = createSandboxClient(found.settings);
|
|
1424
|
+
return made;
|
|
1425
|
+
}),
|
|
1426
|
+
...opts?.webSocket === void 0 ? {} : { webSocket: opts.webSocket },
|
|
1427
|
+
sandboxes: opts?.sandboxes ?? /* @__PURE__ */ new Map(),
|
|
1428
|
+
creating: opts?.creating ?? /* @__PURE__ */ new Set(),
|
|
1429
|
+
joinSecrets: opts?.joinSecrets ?? /* @__PURE__ */ new Map(),
|
|
1430
|
+
sleep: opts?.sleep ?? ((ms) => new Promise((resolve2) => setTimeout(resolve2, ms)))
|
|
1431
|
+
};
|
|
1432
|
+
}
|
|
1433
|
+
|
|
1398
1434
|
// src/runner/verdict.ts
|
|
1399
1435
|
var VERDICT_SETTLE_MS = 5 * 6e4;
|
|
1400
1436
|
var VERDICT_READ_EVERY_MS = 3e4;
|
|
@@ -2273,6 +2309,7 @@ async function decideHostBuildSkill(input, agents = defaultAgents(), job) {
|
|
|
2273
2309
|
}
|
|
2274
2310
|
var BranchPrepareError = class extends Error {
|
|
2275
2311
|
};
|
|
2312
|
+
var KEPT_REF_PREFIX = "refs/outerlayer/kept/";
|
|
2276
2313
|
var OWN_PREFIX = "outerlayer/";
|
|
2277
2314
|
var GIT_TIMEOUT_MS = 12e4;
|
|
2278
2315
|
var REPO_BINDING_GIT_VARS = new Set(
|
|
@@ -2332,13 +2369,30 @@ async function prepareBranch(opts) {
|
|
|
2332
2369
|
} else {
|
|
2333
2370
|
throw new BranchPrepareError(`the pull request's branch ${branch} is not on the remote`);
|
|
2334
2371
|
}
|
|
2372
|
+
const kept = await keepUnpushedCommits(git2, workdir, branch);
|
|
2335
2373
|
await mustGit(git2, workdir, `checking out ${branch}`, ["checkout", "--quiet", "-B", branch, start]);
|
|
2336
2374
|
return {
|
|
2337
2375
|
branch,
|
|
2376
|
+
...kept === void 0 ? {} : { kept },
|
|
2338
2377
|
head: await mustGit(git2, workdir, "reading the checked-out commit", ["rev-parse", "HEAD"]),
|
|
2339
2378
|
startCommit: await mustGit(git2, workdir, `reading the commit of ${defaultBranch}`, ["rev-parse", `origin/${defaultBranch}`])
|
|
2340
2379
|
};
|
|
2341
2380
|
}
|
|
2381
|
+
async function keepUnpushedCommits(git2, workdir, branch) {
|
|
2382
|
+
const local = await git2(workdir, ["rev-parse", "--quiet", "--verify", `refs/heads/${branch}^{commit}`]);
|
|
2383
|
+
if (local.status !== 0) return void 0;
|
|
2384
|
+
const head = local.stdout;
|
|
2385
|
+
const counted = await mustGit(git2, workdir, `counting the commits of ${branch} that no remote branch has`, ["rev-list", "--count", head, "--not", "--remotes"]);
|
|
2386
|
+
const count = Number(counted);
|
|
2387
|
+
if (!(count > 0)) return void 0;
|
|
2388
|
+
const ref = `${KEPT_REF_PREFIX}${head}`;
|
|
2389
|
+
await mustGit(git2, workdir, `keeping the unpushed commits of ${branch}`, ["update-ref", ref, head]);
|
|
2390
|
+
return { count, head, ref };
|
|
2391
|
+
}
|
|
2392
|
+
function keptCommitsLine(branch, kept) {
|
|
2393
|
+
const commits = kept.count === 1 ? "1 commit" : `${kept.count} commits`;
|
|
2394
|
+
return `${branch} at ${kept.head.slice(0, 8)} has ${commits} that no remote branch has. The build does not start from ${kept.count === 1 ? "it" : "them"}, and ${kept.ref} keeps the old head`;
|
|
2395
|
+
}
|
|
2342
2396
|
async function isMerged(git2, workdir, branch, defaultBranch) {
|
|
2343
2397
|
const result = await git2(workdir, ["merge-base", "--is-ancestor", `origin/${branch}`, `origin/${defaultBranch}`]);
|
|
2344
2398
|
if (result.status === 0) return true;
|
|
@@ -2800,6 +2854,7 @@ async function checkOut(input, entry, restored, fromItemDisk) {
|
|
|
2800
2854
|
return { status: ran.status, stdout: ran.stdout.trim(), stderr: ran.stderr.trim() };
|
|
2801
2855
|
}
|
|
2802
2856
|
});
|
|
2857
|
+
if (prepared.kept !== void 0) log.line(`${tag} ${entry.primary ? "" : `${entry.repository}: `}${keptCommitsLine(prepared.branch, prepared.kept)}`);
|
|
2803
2858
|
log.line(`${tag} ${entry.primary ? "" : `${entry.repository} `}on ${prepared.branch} at ${prepared.head.slice(0, 8)}`);
|
|
2804
2859
|
return { ok: true, head: prepared.head, startCommit: prepared.startCommit };
|
|
2805
2860
|
} catch (err) {
|
|
@@ -2947,17 +3002,1071 @@ async function runBuildSteps(input) {
|
|
|
2947
3002
|
} finally {
|
|
2948
3003
|
input.removeStagedContext();
|
|
2949
3004
|
}
|
|
2950
|
-
if (input.aborted()) return aborted();
|
|
3005
|
+
if (input.aborted()) return aborted();
|
|
3006
|
+
}
|
|
3007
|
+
return {
|
|
3008
|
+
ok: true,
|
|
3009
|
+
startCommit,
|
|
3010
|
+
...controlPlane === void 0 ? {} : { controlPlane },
|
|
3011
|
+
...unpinnedRuntimes === void 0 ? {} : { unpinnedRuntimes },
|
|
3012
|
+
...missingSetupScripts === void 0 ? {} : { missingSetupScripts },
|
|
3013
|
+
...savedState ? { savedState: true } : {},
|
|
3014
|
+
...miseVariables === void 0 ? {} : { miseVariables }
|
|
3015
|
+
};
|
|
3016
|
+
}
|
|
3017
|
+
var DeliveryFailure = class extends Error {
|
|
3018
|
+
};
|
|
3019
|
+
var BLOCK2 = 512;
|
|
3020
|
+
var DELIVERY_TIMEOUT_MS = 5 * 6e4;
|
|
3021
|
+
var RECEIVE_ARGV = ["/opt/outerlayer/bin/node", "/opt/outerlayer/cli/dist/index.js", "receive-files"];
|
|
3022
|
+
var REASON_LINE_MAX = 240;
|
|
3023
|
+
var STEPS = {
|
|
3024
|
+
gh: "the build's gh configuration",
|
|
3025
|
+
"git-hooks": "the commit hooks",
|
|
3026
|
+
context: "the staged context",
|
|
3027
|
+
"eval-input": "the checks' input",
|
|
3028
|
+
inbox: "the comments for the agent"
|
|
3029
|
+
};
|
|
3030
|
+
function field(header, at, length, text2) {
|
|
3031
|
+
header.write(text2, at, length, "latin1");
|
|
3032
|
+
}
|
|
3033
|
+
function octalField(header, at, length, value) {
|
|
3034
|
+
field(header, at, length, `${value.toString(8).padStart(length - 1, "0")}\0`);
|
|
3035
|
+
}
|
|
3036
|
+
function tarHeader2(name, type, mode, size) {
|
|
3037
|
+
const header = Buffer.alloc(BLOCK2);
|
|
3038
|
+
header.write(name, 0, 100, "utf8");
|
|
3039
|
+
octalField(header, 100, 8, mode);
|
|
3040
|
+
octalField(header, 108, 8, 0);
|
|
3041
|
+
octalField(header, 116, 8, 0);
|
|
3042
|
+
octalField(header, 124, 12, size);
|
|
3043
|
+
octalField(header, 136, 12, 0);
|
|
3044
|
+
field(header, 148, 8, " ");
|
|
3045
|
+
header.write(type, 156, 1, "latin1");
|
|
3046
|
+
field(header, 257, 6, "ustar\0");
|
|
3047
|
+
field(header, 263, 2, "00");
|
|
3048
|
+
let sum = 0;
|
|
3049
|
+
for (const byte of header) sum += byte;
|
|
3050
|
+
field(header, 148, 8, `${sum.toString(8).padStart(6, "0")}\0 `);
|
|
3051
|
+
return header;
|
|
3052
|
+
}
|
|
3053
|
+
function padded(data) {
|
|
3054
|
+
const rest = data.length % BLOCK2;
|
|
3055
|
+
return rest === 0 ? data : Buffer.concat([data, Buffer.alloc(BLOCK2 - rest)]);
|
|
3056
|
+
}
|
|
3057
|
+
function paxRecord(key, value) {
|
|
3058
|
+
const body = Buffer.from(` ${key}=${value}
|
|
3059
|
+
`, "utf8");
|
|
3060
|
+
let length = body.length + 1;
|
|
3061
|
+
while (String(length).length + body.length !== length) length = String(length).length + body.length;
|
|
3062
|
+
return Buffer.concat([Buffer.from(String(length), "latin1"), body]);
|
|
3063
|
+
}
|
|
3064
|
+
function packTar(entries) {
|
|
3065
|
+
const blocks = [];
|
|
3066
|
+
for (const entry of entries) {
|
|
3067
|
+
const data = entry.type === "file" ? entry.data ?? Buffer.alloc(0) : Buffer.alloc(0);
|
|
3068
|
+
const name = entry.type === "dir" && !entry.path.endsWith("/") ? `${entry.path}/` : entry.path;
|
|
3069
|
+
if (Buffer.byteLength(name, "utf8") > 100) {
|
|
3070
|
+
const record = paxRecord("path", name);
|
|
3071
|
+
blocks.push(tarHeader2("PaxHeader", "x", 420, record.length), padded(record));
|
|
3072
|
+
}
|
|
3073
|
+
blocks.push(tarHeader2(name, entry.type === "dir" ? "5" : "0", entry.mode, data.length), padded(data));
|
|
3074
|
+
}
|
|
3075
|
+
blocks.push(Buffer.alloc(BLOCK2 * 2));
|
|
3076
|
+
return Buffer.concat(blocks);
|
|
3077
|
+
}
|
|
3078
|
+
function fileMode(hostMode) {
|
|
3079
|
+
return 292 | hostMode & 128 | ((hostMode & 73) === 0 ? 0 : 73);
|
|
3080
|
+
}
|
|
3081
|
+
function packFolder(dir, options = {}) {
|
|
3082
|
+
const entries = options.rootMode === void 0 ? [] : [{ path: "./", type: "dir", mode: options.rootMode }];
|
|
3083
|
+
const walk = (current, prefix) => {
|
|
3084
|
+
for (const name of readdirSync(current).sort()) {
|
|
3085
|
+
const path = join(current, name);
|
|
3086
|
+
const stat = lstatSync(path);
|
|
3087
|
+
const rel = prefix === "" ? name : `${prefix}/${name}`;
|
|
3088
|
+
if (stat.isDirectory()) {
|
|
3089
|
+
entries.push({ path: rel, type: "dir", mode: options.dirModes?.[rel] ?? 493 });
|
|
3090
|
+
walk(path, rel);
|
|
3091
|
+
} else if (stat.isFile()) {
|
|
3092
|
+
entries.push({ path: rel, type: "file", mode: fileMode(stat.mode), data: readFileSync(path) });
|
|
3093
|
+
}
|
|
3094
|
+
}
|
|
3095
|
+
};
|
|
3096
|
+
walk(dir, "");
|
|
3097
|
+
return packTar(entries);
|
|
3098
|
+
}
|
|
3099
|
+
function scrubDelivery(text2, secrets) {
|
|
3100
|
+
let out = text2.replace(/\u001b\[[0-?]*[ -/]*[@-~]/g, "").replace(/[\u0000-\u001f\u007f-\u009f]/g, " ");
|
|
3101
|
+
for (const secret of secrets()) if (secret !== "") out = out.split(secret).join("[redacted]");
|
|
3102
|
+
out = out.replace(/\b(?:gh[pousr]_|github_pat_)[A-Za-z0-9_]+/g, "[redacted]");
|
|
3103
|
+
out = out.trim();
|
|
3104
|
+
return out.length > REASON_LINE_MAX ? `${out.slice(0, REASON_LINE_MAX)}...` : out;
|
|
3105
|
+
}
|
|
3106
|
+
async function deliverTar(runtime, state, input) {
|
|
3107
|
+
try {
|
|
3108
|
+
const result = await runtime.host.exec(
|
|
3109
|
+
{
|
|
3110
|
+
container: state.container,
|
|
3111
|
+
user: RELAY_USER,
|
|
3112
|
+
env: { literals: {}, passed: {} },
|
|
3113
|
+
argv: [...RECEIVE_ARGV, "--into", input.into, ...input.replace === true ? ["--replace"] : []],
|
|
3114
|
+
stdin: input.tar
|
|
3115
|
+
},
|
|
3116
|
+
{ timeoutMs: DELIVERY_TIMEOUT_MS }
|
|
3117
|
+
);
|
|
3118
|
+
if (result.status === 0) return { ok: true };
|
|
3119
|
+
const line2 = scrubDelivery(result.stderr.trim().split("\n")[0] ?? "", input.secrets);
|
|
3120
|
+
return { ok: false, reason: `${input.step} could not be delivered (exit ${result.status})${line2 === "" ? "" : `: ${line2}`}` };
|
|
3121
|
+
} catch (err) {
|
|
3122
|
+
return { ok: false, reason: `${input.step} could not be delivered: ${scrubDelivery(describeCallFailure(err), input.secrets)}` };
|
|
3123
|
+
}
|
|
3124
|
+
}
|
|
3125
|
+
async function deliverJobFiles(runtime, state, parts, secrets) {
|
|
3126
|
+
for (const part of parts) {
|
|
3127
|
+
const dir = join(state.buildDir, part === "eval-input" ? EVAL_INPUT_NAME : part);
|
|
3128
|
+
if (!existsSync(dir)) continue;
|
|
3129
|
+
let tar;
|
|
3130
|
+
try {
|
|
3131
|
+
tar = packFolder(dir);
|
|
3132
|
+
} catch (err) {
|
|
3133
|
+
return { ok: false, reason: `${STEPS[part]} could not be read on the host: ${scrubDelivery(describeCallFailure(err), secrets)}` };
|
|
3134
|
+
}
|
|
3135
|
+
const delivered = await deliverTar(runtime, state, { step: STEPS[part], tar, into: `${JOB_MOUNT}/${part}`, replace: part === "eval-input", secrets });
|
|
3136
|
+
if (!delivered.ok) return delivered;
|
|
3137
|
+
}
|
|
3138
|
+
return { ok: true };
|
|
3139
|
+
}
|
|
3140
|
+
function deliverGhConfig(runtime, state, secrets) {
|
|
3141
|
+
return deliverJobFiles(runtime, state, ["gh"], secrets);
|
|
3142
|
+
}
|
|
3143
|
+
function deliverEvalInput(runtime, state, secrets) {
|
|
3144
|
+
return deliverJobFiles(runtime, state, ["eval-input"], secrets);
|
|
3145
|
+
}
|
|
3146
|
+
async function deliverJudgeInputs(runtime, state, dir, secrets) {
|
|
3147
|
+
return deliverTar(runtime, state, { step: "the judge's inputs", tar: packFolder(dir, { rootMode: 1023, dirModes: { home: 511, "home/tmp": 511 } }), into: JUDGE_DIR, replace: true, secrets });
|
|
3148
|
+
}
|
|
3149
|
+
function clearJudgeFolder(runtime, state, secrets) {
|
|
3150
|
+
return deliverTar(runtime, state, { step: "clearing the judge's folder", tar: packTar([]), into: JUDGE_DIR, replace: true, secrets });
|
|
3151
|
+
}
|
|
3152
|
+
var FILE_MODE = 420;
|
|
3153
|
+
var DIR_MODE = 493;
|
|
3154
|
+
function replaceFile(path, text2) {
|
|
3155
|
+
const partial = `${path}.${process.pid}.partial`;
|
|
3156
|
+
writeFileSync(partial, text2);
|
|
3157
|
+
chmodSync(partial, FILE_MODE);
|
|
3158
|
+
renameSync(partial, path);
|
|
3159
|
+
}
|
|
3160
|
+
function ghHostsYml(token) {
|
|
3161
|
+
return [
|
|
3162
|
+
"github.com:",
|
|
3163
|
+
" users:",
|
|
3164
|
+
" x-access-token:",
|
|
3165
|
+
` oauth_token: ${token}`,
|
|
3166
|
+
` oauth_token: ${token}`,
|
|
3167
|
+
" user: x-access-token",
|
|
3168
|
+
" git_protocol: https",
|
|
3169
|
+
""
|
|
3170
|
+
].join("\n");
|
|
3171
|
+
}
|
|
3172
|
+
var GH_CONFIG_YML = 'version: "1"\n';
|
|
3173
|
+
function writeGhConfig(dir, token) {
|
|
3174
|
+
mkdirSync(dir, { recursive: true, mode: DIR_MODE });
|
|
3175
|
+
chmodSync(dir, DIR_MODE);
|
|
3176
|
+
replaceFile(join(dir, "hosts.yml"), ghHostsYml(token));
|
|
3177
|
+
replaceFile(join(dir, "config.yml"), GH_CONFIG_YML);
|
|
3178
|
+
}
|
|
3179
|
+
var noop = () => void 0;
|
|
3180
|
+
var FRAME_HEADER_BYTES = 9;
|
|
3181
|
+
var GOAWAY_FRAME = 7;
|
|
3182
|
+
function describeGoawayCode(code) {
|
|
3183
|
+
const names = [
|
|
3184
|
+
"NO_ERROR",
|
|
3185
|
+
"PROTOCOL_ERROR",
|
|
3186
|
+
"INTERNAL_ERROR",
|
|
3187
|
+
"FLOW_CONTROL_ERROR",
|
|
3188
|
+
"SETTINGS_TIMEOUT",
|
|
3189
|
+
"STREAM_CLOSED",
|
|
3190
|
+
"FRAME_SIZE_ERROR",
|
|
3191
|
+
"REFUSED_STREAM",
|
|
3192
|
+
"CANCEL",
|
|
3193
|
+
"COMPRESSION_ERROR",
|
|
3194
|
+
"CONNECT_ERROR",
|
|
3195
|
+
"ENHANCE_YOUR_CALM",
|
|
3196
|
+
"INADEQUATE_SECURITY",
|
|
3197
|
+
"HTTP_1_1_REQUIRED"
|
|
3198
|
+
];
|
|
3199
|
+
const name = names[code];
|
|
3200
|
+
return name === void 0 ? `error code ${code}` : `${name} (${code})`;
|
|
3201
|
+
}
|
|
3202
|
+
function goawayNote(label, code) {
|
|
3203
|
+
return code === void 0 ? "" : ` \xB7 ${label} ${describeGoawayCode(code)}`;
|
|
3204
|
+
}
|
|
3205
|
+
function watchSentGoaway(onError) {
|
|
3206
|
+
let head = Buffer.alloc(0);
|
|
3207
|
+
let want = FRAME_HEADER_BYTES;
|
|
3208
|
+
let skip = 0;
|
|
3209
|
+
return (chunk) => {
|
|
3210
|
+
let at = 0;
|
|
3211
|
+
while (at < chunk.length) {
|
|
3212
|
+
if (skip > 0) {
|
|
3213
|
+
const n = Math.min(skip, chunk.length - at);
|
|
3214
|
+
skip -= n;
|
|
3215
|
+
at += n;
|
|
3216
|
+
continue;
|
|
3217
|
+
}
|
|
3218
|
+
const take = Math.min(want - head.length, chunk.length - at);
|
|
3219
|
+
head = Buffer.concat([head, chunk.subarray(at, at + take)]);
|
|
3220
|
+
at += take;
|
|
3221
|
+
if (head.length < want) return;
|
|
3222
|
+
const length = head.readUIntBE(0, 3);
|
|
3223
|
+
if (want === FRAME_HEADER_BYTES && head[3] === GOAWAY_FRAME && length >= 8) {
|
|
3224
|
+
want = FRAME_HEADER_BYTES + 8;
|
|
3225
|
+
continue;
|
|
3226
|
+
}
|
|
3227
|
+
if (want > FRAME_HEADER_BYTES) {
|
|
3228
|
+
const code = head.readUInt32BE(FRAME_HEADER_BYTES + 4);
|
|
3229
|
+
if (code !== http2.constants.NGHTTP2_NO_ERROR) onError(code);
|
|
3230
|
+
}
|
|
3231
|
+
skip = length - (want - FRAME_HEADER_BYTES);
|
|
3232
|
+
head = Buffer.alloc(0);
|
|
3233
|
+
want = FRAME_HEADER_BYTES;
|
|
3234
|
+
}
|
|
3235
|
+
};
|
|
3236
|
+
}
|
|
3237
|
+
function writeStringsAsBuffers(stream) {
|
|
3238
|
+
const own = stream._writev;
|
|
3239
|
+
if (typeof own !== "function") return;
|
|
3240
|
+
stream._writev = function(chunks, callback) {
|
|
3241
|
+
const buffers = chunks.map(({ chunk, encoding }) => ({
|
|
3242
|
+
chunk: typeof chunk === "string" ? Buffer.from(chunk, encoding) : chunk,
|
|
3243
|
+
encoding: "buffer"
|
|
3244
|
+
}));
|
|
3245
|
+
buffers.allBuffers = true;
|
|
3246
|
+
own.call(this, buffers, callback);
|
|
3247
|
+
};
|
|
3248
|
+
}
|
|
3249
|
+
function serveSession(transport, services, opts = {}) {
|
|
3250
|
+
const maxStreams = opts.maxStreams ?? MAX_OPEN_STREAMS;
|
|
3251
|
+
let open = 0;
|
|
3252
|
+
let served = 0;
|
|
3253
|
+
let malformed = false;
|
|
3254
|
+
let goawayCode;
|
|
3255
|
+
transport.on("error", noop);
|
|
3256
|
+
const watch = watchSentGoaway((code) => {
|
|
3257
|
+
malformed = true;
|
|
3258
|
+
goawayCode ??= code;
|
|
3259
|
+
setImmediate(() => session.destroy());
|
|
3260
|
+
});
|
|
3261
|
+
const outbound = new Transform({
|
|
3262
|
+
transform(chunk, _encoding, done) {
|
|
3263
|
+
watch(chunk);
|
|
3264
|
+
done(null, chunk);
|
|
3265
|
+
}
|
|
3266
|
+
});
|
|
3267
|
+
outbound.on("error", noop);
|
|
3268
|
+
outbound.pipe(transport);
|
|
3269
|
+
const wire = Duplex.from({ readable: transport, writable: outbound });
|
|
3270
|
+
wire.on("error", noop);
|
|
3271
|
+
const session = http2.performServerHandshake(wire, {
|
|
3272
|
+
settings: { initialWindowSize: STREAM_WINDOW, enablePush: false },
|
|
3273
|
+
streamResetBurst: STREAM_RESET_BURST,
|
|
3274
|
+
streamResetRate: STREAM_RESET_RATE
|
|
3275
|
+
});
|
|
3276
|
+
try {
|
|
3277
|
+
session.setLocalWindowSize(SESSION_WINDOW);
|
|
3278
|
+
} catch {
|
|
3279
|
+
}
|
|
3280
|
+
const ended = new Promise((resolve2) => {
|
|
3281
|
+
session.on("error", (err) => {
|
|
3282
|
+
if (typeof err.code === "string" && err.code.startsWith("ERR_HTTP2_")) malformed = true;
|
|
3283
|
+
});
|
|
3284
|
+
session.on("goaway", (code) => {
|
|
3285
|
+
if (code !== http2.constants.NGHTTP2_NO_ERROR) goawayCode ??= code;
|
|
3286
|
+
});
|
|
3287
|
+
session.on("close", () => resolve2({ malformed, served, goawayCode }));
|
|
3288
|
+
});
|
|
3289
|
+
session.on("stream", (stream, headers) => {
|
|
3290
|
+
stream.on("error", noop);
|
|
3291
|
+
const target2 = headers[":method"] === "POST" ? targetOfPath(headers[":path"], opts.builtIns) : void 0;
|
|
3292
|
+
if (target2 === void 0 || open >= maxStreams) {
|
|
3293
|
+
stream.close(http2.constants.NGHTTP2_REFUSED_STREAM);
|
|
3294
|
+
return;
|
|
3295
|
+
}
|
|
3296
|
+
open++;
|
|
3297
|
+
stream.once("close", () => {
|
|
3298
|
+
open--;
|
|
3299
|
+
});
|
|
3300
|
+
writeStringsAsBuffers(stream);
|
|
3301
|
+
if (!services.accept(target2, stream)) {
|
|
3302
|
+
stream.close(http2.constants.NGHTTP2_REFUSED_STREAM);
|
|
3303
|
+
return;
|
|
3304
|
+
}
|
|
3305
|
+
served++;
|
|
3306
|
+
if (!stream.headersSent && !stream.destroyed) stream.respond({ ":status": 200 });
|
|
3307
|
+
});
|
|
3308
|
+
return {
|
|
3309
|
+
ended,
|
|
3310
|
+
// A session the peer is closing gracefully waits for its open streams, which a stopped container never ends: destroy it whatever its state.
|
|
3311
|
+
close: () => {
|
|
3312
|
+
if (!session.destroyed) session.destroy();
|
|
3313
|
+
}
|
|
3314
|
+
};
|
|
3315
|
+
}
|
|
3316
|
+
var FIRST_BACKOFF_MS = 200;
|
|
3317
|
+
var LONGEST_BACKOFF_MS = 5e3;
|
|
3318
|
+
var JOINED_AFTER_MS = 2e3;
|
|
3319
|
+
var EXIT_WAIT_MS = 5e3;
|
|
3320
|
+
var SOCKET_NOT_READY = /\b(ENOENT|ECONNREFUSED)\b/;
|
|
3321
|
+
function exitedWithin(stream, ms) {
|
|
3322
|
+
let timer;
|
|
3323
|
+
const late = new Promise((resolve2) => {
|
|
3324
|
+
timer = setTimeout(() => resolve2(void 0), ms);
|
|
3325
|
+
timer.unref();
|
|
3326
|
+
});
|
|
3327
|
+
return Promise.race([stream.exited, late]).finally(() => clearTimeout(timer));
|
|
3328
|
+
}
|
|
3329
|
+
function superviseRelay(input) {
|
|
3330
|
+
const sleep = input.sleep ?? ((ms) => new Promise((resolve2) => setTimeout(resolve2, ms)));
|
|
3331
|
+
const exitWaitMs = input.exitWaitMs ?? EXIT_WAIT_MS;
|
|
3332
|
+
const now = input.now ?? Date.now;
|
|
3333
|
+
const startedAt = now();
|
|
3334
|
+
let closed = false;
|
|
3335
|
+
let fatal;
|
|
3336
|
+
let running;
|
|
3337
|
+
let wake;
|
|
3338
|
+
const loop = (async () => {
|
|
3339
|
+
let malformedInARow = 0;
|
|
3340
|
+
let backoff = FIRST_BACKOFF_MS;
|
|
3341
|
+
let failing = false;
|
|
3342
|
+
while (!closed && fatal === void 0) {
|
|
3343
|
+
const startedMs = Date.now();
|
|
3344
|
+
const stream = input.execStream({
|
|
3345
|
+
container: input.container,
|
|
3346
|
+
user: RELAY_USER,
|
|
3347
|
+
env: { literals: {}, passed: {} },
|
|
3348
|
+
argv: ["outerlayer", "broker-relay", "join"],
|
|
3349
|
+
interactive: true
|
|
3350
|
+
});
|
|
3351
|
+
stream.stdin.on("error", noop);
|
|
3352
|
+
stream.stdout.on("error", noop);
|
|
3353
|
+
const session = serveSession(Duplex.from({ readable: stream.stdout, writable: stream.stdin }), input.services, { builtIns: input.builtIns });
|
|
3354
|
+
running = { stream, session };
|
|
3355
|
+
void stream.exited.then(() => session.close());
|
|
3356
|
+
const end = await session.ended;
|
|
3357
|
+
stream.kill();
|
|
3358
|
+
const status = await exitedWithin(stream, exitWaitMs);
|
|
3359
|
+
running = void 0;
|
|
3360
|
+
if (status === void 0) input.log?.(`the relay's exec into ${input.container} did not end when killed \xB7 going on without it`);
|
|
3361
|
+
const joined = end.served > 0 || Date.now() - startedMs >= JOINED_AFTER_MS;
|
|
3362
|
+
if (joined) {
|
|
3363
|
+
backoff = FIRST_BACKOFF_MS;
|
|
3364
|
+
failing = false;
|
|
3365
|
+
if (!closed) input.log?.(`the session with ${input.container} ended \xB7 joining again${goawayNote("GOAWAY", end.goawayCode)}`);
|
|
3366
|
+
}
|
|
3367
|
+
if (!end.malformed && end.served > 0) malformedInARow = 0;
|
|
3368
|
+
if (end.malformed) {
|
|
3369
|
+
malformedInARow++;
|
|
3370
|
+
if (malformedInARow >= MAX_MALFORMED_SESSIONS) {
|
|
3371
|
+
fatal = MALFORMED_REASON;
|
|
3372
|
+
input.log?.(`the session with ${input.container} broke HTTP/2 framing ${malformedInARow} times in a row${goawayNote("last GOAWAY", end.goawayCode)} \xB7 ending the build`);
|
|
3373
|
+
input.onFatal?.(fatal);
|
|
3374
|
+
return;
|
|
3375
|
+
}
|
|
3376
|
+
} else if (!joined && !failing) {
|
|
3377
|
+
const reason = stream.stderrTail?.().trim() ?? "";
|
|
3378
|
+
const starting = SOCKET_NOT_READY.test(reason) && now() - startedAt < JOIN_WAIT_MS;
|
|
3379
|
+
if (!starting) {
|
|
3380
|
+
failing = true;
|
|
3381
|
+
input.log?.(`could not join the relay in ${input.container}${status === 0 || status === void 0 ? "" : ` (exec exited ${status})`}${reason === "" ? "" : `: ${reason}`} \xB7 trying again`);
|
|
3382
|
+
}
|
|
3383
|
+
}
|
|
3384
|
+
if (closed) return;
|
|
3385
|
+
await Promise.race([sleep(backoff), new Promise((resolve2) => wake = resolve2)]);
|
|
3386
|
+
backoff = Math.min(backoff * 2, LONGEST_BACKOFF_MS);
|
|
3387
|
+
}
|
|
3388
|
+
})();
|
|
3389
|
+
return {
|
|
3390
|
+
fatal: () => fatal,
|
|
3391
|
+
close: async () => {
|
|
3392
|
+
closed = true;
|
|
3393
|
+
wake?.();
|
|
3394
|
+
running?.session.close();
|
|
3395
|
+
running?.stream.kill();
|
|
3396
|
+
await loop;
|
|
3397
|
+
}
|
|
3398
|
+
};
|
|
3399
|
+
}
|
|
3400
|
+
|
|
3401
|
+
// src/runner/record-proofs.ts
|
|
3402
|
+
var RECORD_PROOFS_ARGV = ["outerlayer", "work", "proofs", "--record", "--comment"];
|
|
3403
|
+
var PROOFS_LOG = "proofs.log";
|
|
3404
|
+
|
|
3405
|
+
// src/runner/sandbox/sweep.ts
|
|
3406
|
+
var RUNNER_METADATA = "outerlayerRunner";
|
|
3407
|
+
var BUILD_METADATA = "outerlayerBuild";
|
|
3408
|
+
function orphanedSandboxes(sandboxes, runnerId, heldBuilds) {
|
|
3409
|
+
return sandboxes.filter((sandbox) => {
|
|
3410
|
+
if (sandbox.metadata[RUNNER_METADATA] !== runnerId) return false;
|
|
3411
|
+
if (sandbox.state === "ended") return false;
|
|
3412
|
+
const build = sandbox.metadata[BUILD_METADATA];
|
|
3413
|
+
return build === void 0 || !heldBuilds.has(build);
|
|
3414
|
+
});
|
|
3415
|
+
}
|
|
3416
|
+
async function sweepSandboxes(input) {
|
|
3417
|
+
let listed;
|
|
3418
|
+
try {
|
|
3419
|
+
listed = await input.client.list();
|
|
3420
|
+
} catch (err) {
|
|
3421
|
+
input.log?.(`could not list sandboxes: ${err instanceof Error ? err.message : String(err)}`);
|
|
3422
|
+
return 0;
|
|
3423
|
+
}
|
|
3424
|
+
let ended = 0;
|
|
3425
|
+
for (const sandbox of orphanedSandboxes(listed, input.runnerId, input.heldBuilds())) {
|
|
3426
|
+
try {
|
|
3427
|
+
await input.client.end(sandbox.id);
|
|
3428
|
+
ended++;
|
|
3429
|
+
input.log?.(`ended sandbox ${sandbox.id} (${sandbox.name}): no unfinished build holds it`);
|
|
3430
|
+
} catch (err) {
|
|
3431
|
+
input.log?.(`could not end sandbox ${sandbox.id}: ${err instanceof Error ? err.message : String(err)}`);
|
|
3432
|
+
}
|
|
3433
|
+
}
|
|
3434
|
+
return ended;
|
|
3435
|
+
}
|
|
3436
|
+
var BUFFER_HIGH_WATER = 1024 * 1024;
|
|
3437
|
+
var DRAIN_POLL_MS = 5;
|
|
3438
|
+
var OPEN_TIMEOUT_MS = 3e4;
|
|
3439
|
+
var defaultWebSocket = (url) => new WebSocket(url);
|
|
3440
|
+
function sandboxExecStream(opts) {
|
|
3441
|
+
const create = opts.webSocket ?? defaultWebSocket;
|
|
3442
|
+
return () => {
|
|
3443
|
+
const stdout = new PassThrough();
|
|
3444
|
+
let socket;
|
|
3445
|
+
let open = false;
|
|
3446
|
+
let finished2 = false;
|
|
3447
|
+
let tail = "";
|
|
3448
|
+
let finish2;
|
|
3449
|
+
const exited = new Promise((resolve2) => finish2 = resolve2);
|
|
3450
|
+
const end = (status, why) => {
|
|
3451
|
+
if (finished2) return;
|
|
3452
|
+
finished2 = true;
|
|
3453
|
+
if (why !== void 0) tail = `${tail}${why}`.slice(-400);
|
|
3454
|
+
stdout.end();
|
|
3455
|
+
try {
|
|
3456
|
+
socket?.close();
|
|
3457
|
+
} catch {
|
|
3458
|
+
}
|
|
3459
|
+
finish2(status);
|
|
3460
|
+
};
|
|
3461
|
+
const opened = new Promise((resolve2, reject) => {
|
|
3462
|
+
const timer = setTimeout(() => reject(new Error("the WebSocket did not open in time")), OPEN_TIMEOUT_MS);
|
|
3463
|
+
timer.unref();
|
|
3464
|
+
opts.url().then((url) => {
|
|
3465
|
+
socket = create(url);
|
|
3466
|
+
socket.binaryType = "arraybuffer";
|
|
3467
|
+
socket.addEventListener("open", () => {
|
|
3468
|
+
clearTimeout(timer);
|
|
3469
|
+
open = true;
|
|
3470
|
+
socket.send(opts.secret);
|
|
3471
|
+
resolve2();
|
|
3472
|
+
});
|
|
3473
|
+
socket.addEventListener("message", (event) => {
|
|
3474
|
+
if (event.data instanceof ArrayBuffer) stdout.write(Buffer.from(event.data));
|
|
3475
|
+
else if (ArrayBuffer.isView(event.data)) stdout.write(Buffer.from(event.data.buffer, event.data.byteOffset, event.data.byteLength));
|
|
3476
|
+
});
|
|
3477
|
+
socket.addEventListener("error", (event) => {
|
|
3478
|
+
clearTimeout(timer);
|
|
3479
|
+
reject(new Error(event.message ?? "the WebSocket failed"));
|
|
3480
|
+
});
|
|
3481
|
+
socket.addEventListener("close", (event) => {
|
|
3482
|
+
clearTimeout(timer);
|
|
3483
|
+
reject(new Error("the WebSocket closed before it opened"));
|
|
3484
|
+
end(event.code === 1e3 || event.code === void 0 ? 0 : 1, event.code === 1008 ? "the relay refused the join secret" : void 0);
|
|
3485
|
+
});
|
|
3486
|
+
}).catch((err) => {
|
|
3487
|
+
clearTimeout(timer);
|
|
3488
|
+
reject(err);
|
|
3489
|
+
});
|
|
3490
|
+
});
|
|
3491
|
+
opened.catch((err) => end(1, err instanceof Error ? err.message : String(err)));
|
|
3492
|
+
const stdin = new Writable({
|
|
3493
|
+
write(chunk, _encoding, callback) {
|
|
3494
|
+
opened.then(
|
|
3495
|
+
async () => {
|
|
3496
|
+
if (finished2) return callback(new Error("the connection is closed"));
|
|
3497
|
+
socket.send(chunk);
|
|
3498
|
+
while (open && !finished2 && socket.bufferedAmount > BUFFER_HIGH_WATER) await new Promise((resolve2) => setTimeout(resolve2, DRAIN_POLL_MS));
|
|
3499
|
+
callback();
|
|
3500
|
+
},
|
|
3501
|
+
() => callback(new Error("the connection did not open"))
|
|
3502
|
+
);
|
|
3503
|
+
},
|
|
3504
|
+
final(callback) {
|
|
3505
|
+
end(0);
|
|
3506
|
+
callback();
|
|
3507
|
+
}
|
|
3508
|
+
});
|
|
3509
|
+
stdin.on("error", () => void 0);
|
|
3510
|
+
stdout.on("error", () => void 0);
|
|
3511
|
+
return { stdin, stdout, exited, kill: () => end(-1), stderrTail: () => tail };
|
|
3512
|
+
};
|
|
3513
|
+
}
|
|
3514
|
+
var RUN_DIR = "/tmp/ol-run";
|
|
3515
|
+
var CHUNK_BYTES = 9e4;
|
|
3516
|
+
var READ_ATTEMPTS = 4;
|
|
3517
|
+
var POLL_FIRST_MS = 50;
|
|
3518
|
+
var POLL_LONGEST_MS = 1e3;
|
|
3519
|
+
function quote(word) {
|
|
3520
|
+
return /^[A-Za-z0-9_@%+=:,./-]+$/.test(word) ? word : `'${word.replace(/'/g, `'\\''`)}'`;
|
|
3521
|
+
}
|
|
3522
|
+
function sandboxLine(command, args, env) {
|
|
3523
|
+
const values = Object.entries(env ?? {}).filter((entry) => entry[1] !== void 0).map(([name, value]) => `${name}=${quote(value)}`);
|
|
3524
|
+
return ["sudo", "env", ...values, command, ...args.map(quote)].join(" ");
|
|
3525
|
+
}
|
|
3526
|
+
function sandboxRunner(client2, sandbox, options = {}) {
|
|
3527
|
+
const sleep = options.sleep ?? ((ms) => new Promise((resolve2) => setTimeout(resolve2, ms)));
|
|
3528
|
+
return async (command, args, opts = {}) => {
|
|
3529
|
+
const id = randomBytes(6).toString("hex");
|
|
3530
|
+
const file = (suffix) => `${RUN_DIR}/${id}.${suffix}`;
|
|
3531
|
+
const line2 = sandboxLine(command, args, opts.env);
|
|
3532
|
+
options.onCommand?.(line2);
|
|
3533
|
+
if (opts.input !== void 0) {
|
|
3534
|
+
await client2.command(sandbox, `mkdir -p ${RUN_DIR}`);
|
|
3535
|
+
await client2.upload(sandbox, file("in"), Buffer.isBuffer(opts.input) ? opts.input : Buffer.from(opts.input));
|
|
3536
|
+
}
|
|
3537
|
+
const start = `mkdir -p ${RUN_DIR}; echo $$ > ${file("pid")}; ${line2} < ${opts.input === void 0 ? "/dev/null" : file("in")} > ${file("out")} 2> ${file("err")}; echo $? > ${file("code.tmp")}; mv -f ${file("code.tmp")} ${file("code")}`;
|
|
3538
|
+
await client2.command(sandbox, start, { background: true });
|
|
3539
|
+
const deadline = opts.timeoutMs === void 0 ? void 0 : Date.now() + opts.timeoutMs;
|
|
3540
|
+
const collect = `if [ -f ${file("code")} ]; then cat ${file("code")}; head -c ${CHUNK_BYTES} ${file("out")} | base64 | tr -d '\\n'; echo; head -c ${CHUNK_BYTES} ${file("err")} | base64 | tr -d '\\n'; echo; wc -c < ${file("out")}; wc -c < ${file("err")}; fi`;
|
|
3541
|
+
const ask2 = async (cmd) => {
|
|
3542
|
+
for (let attempt = 1; ; attempt++) {
|
|
3543
|
+
try {
|
|
3544
|
+
return await client2.command(sandbox, cmd);
|
|
3545
|
+
} catch (err) {
|
|
3546
|
+
const transient = err instanceof SandboxError && (err.status === 0 || err.status >= 500);
|
|
3547
|
+
if (!transient || attempt >= READ_ATTEMPTS) throw err;
|
|
3548
|
+
await sleep(POLL_FIRST_MS * attempt);
|
|
3549
|
+
}
|
|
3550
|
+
}
|
|
3551
|
+
};
|
|
3552
|
+
let wait = POLL_FIRST_MS;
|
|
3553
|
+
for (; ; ) {
|
|
3554
|
+
const polled = await ask2(collect);
|
|
3555
|
+
if (polled.stdout.trim() !== "") {
|
|
3556
|
+
const [code = "", out = "", err = "", outSize = "0", errSize = "0"] = polled.stdout.split("\n").map((part) => part.trim());
|
|
3557
|
+
const pieces = [Buffer.from(out, "base64")];
|
|
3558
|
+
const errPieces = [Buffer.from(err, "base64")];
|
|
3559
|
+
const more = async (name, size, into) => {
|
|
3560
|
+
for (let read = CHUNK_BYTES; read < size; read += CHUNK_BYTES) {
|
|
3561
|
+
const next = await ask2(`tail -c +${read + 1} ${file(name)} | head -c ${CHUNK_BYTES} | base64 | tr -d '\\n'`);
|
|
3562
|
+
into.push(Buffer.from(next.stdout.trim(), "base64"));
|
|
3563
|
+
}
|
|
3564
|
+
};
|
|
3565
|
+
await more("out", Number(outSize), pieces);
|
|
3566
|
+
await more("err", Number(errSize), errPieces);
|
|
3567
|
+
await client2.command(sandbox, `rm -f ${RUN_DIR}/${id}.*`);
|
|
3568
|
+
const result = { status: Number(code) || 0, stdout: Buffer.concat(pieces).toString("utf8"), stderr: Buffer.concat(errPieces).toString("utf8") };
|
|
3569
|
+
if (opts.logPath !== void 0) {
|
|
3570
|
+
mkdirSync(dirname(opts.logPath), { recursive: true });
|
|
3571
|
+
appendFileSync(opts.logPath, result.stdout + result.stderr);
|
|
3572
|
+
}
|
|
3573
|
+
return result;
|
|
3574
|
+
}
|
|
3575
|
+
if (deadline !== void 0 && Date.now() >= deadline) {
|
|
3576
|
+
await client2.command(sandbox, `kill -9 $(cat ${file("pid")}) 2>/dev/null; rm -f ${RUN_DIR}/${id}.*`).catch(() => void 0);
|
|
3577
|
+
const extra = `${command}: no answer within ${Math.round(opts.timeoutMs / 1e3)}s
|
|
3578
|
+
`;
|
|
3579
|
+
if (opts.logPath !== void 0) {
|
|
3580
|
+
mkdirSync(dirname(opts.logPath), { recursive: true });
|
|
3581
|
+
appendFileSync(opts.logPath, extra);
|
|
3582
|
+
}
|
|
3583
|
+
return { status: 124, stdout: "", stderr: extra };
|
|
3584
|
+
}
|
|
3585
|
+
await sleep(wait);
|
|
3586
|
+
wait = Math.min(wait * 2, POLL_LONGEST_MS);
|
|
3587
|
+
}
|
|
3588
|
+
};
|
|
3589
|
+
}
|
|
3590
|
+
function sandboxHost(client2, sandbox, options = {}) {
|
|
3591
|
+
return createContainerHost({ run: sandboxRunner(client2, sandbox, options) });
|
|
3592
|
+
}
|
|
3593
|
+
|
|
3594
|
+
// src/runner/sandbox/hooks.ts
|
|
3595
|
+
var SANDBOX_DIR = "/tmp/ol";
|
|
3596
|
+
var CLI_DIR = `${SANDBOX_DIR}/dist`;
|
|
3597
|
+
var SECRET_FILE = `${SANDBOX_DIR}/join-secret`;
|
|
3598
|
+
var CONTAINER_SECRET_FILE = "/run/outerlayer-relay/join-secret";
|
|
3599
|
+
var JOIN_WS_PORT = 7077;
|
|
3600
|
+
var SANDBOX_RESERVE_MIB = 512;
|
|
3601
|
+
var RELAY_ATTEMPTS = 40;
|
|
3602
|
+
var RELAY_WAIT_MS = 500;
|
|
3603
|
+
var SANDBOX_PROBE_BYTES = 96 * 1024;
|
|
3604
|
+
var MAX_TAIL_READS2 = 8;
|
|
3605
|
+
var NO_ENV = { literals: {}, passed: {} };
|
|
3606
|
+
function sandboxNameOf(runnerLabel, buildId) {
|
|
3607
|
+
const short = runnerLabel.toLowerCase().replace(/[^a-z0-9]/g, "").slice(0, 8);
|
|
3608
|
+
return `ol-${short === "" ? "runner" : short}-${buildId}`;
|
|
3609
|
+
}
|
|
3610
|
+
async function endUnansweredSandbox(sandboxClient, runnerId, buildId, warn) {
|
|
3611
|
+
try {
|
|
3612
|
+
for (const found of await sandboxClient.list()) {
|
|
3613
|
+
if (found.state !== "ended" && found.metadata[RUNNER_METADATA] === runnerId && found.metadata[BUILD_METADATA] === buildId) await sandboxClient.end(found.id);
|
|
3614
|
+
}
|
|
3615
|
+
} catch (err) {
|
|
3616
|
+
warn(`could not end a sandbox that a lost create may have made: ${describeCallFailure(err)} \xB7 the next sweep ends it`);
|
|
3617
|
+
}
|
|
3618
|
+
}
|
|
3619
|
+
function client(runtime) {
|
|
3620
|
+
return runtime.sandbox.client();
|
|
3621
|
+
}
|
|
3622
|
+
async function sandboxOfBuild(runtime, state) {
|
|
3623
|
+
const held3 = runtime.sandbox.sandboxes.get(state.buildId);
|
|
3624
|
+
if (held3 !== void 0) return held3;
|
|
3625
|
+
try {
|
|
3626
|
+
const found = await client(runtime).get(state.sandboxId);
|
|
3627
|
+
if (found.state === "ended" || found.secret === "") return void 0;
|
|
3628
|
+
runtime.sandbox.sandboxes.set(state.buildId, found);
|
|
3629
|
+
return found;
|
|
3630
|
+
} catch (err) {
|
|
3631
|
+
if (err instanceof SandboxError && err.status === 404) return void 0;
|
|
3632
|
+
throw err;
|
|
3633
|
+
}
|
|
3634
|
+
}
|
|
3635
|
+
function runtimeInSandbox(runtime, sandbox) {
|
|
3636
|
+
return { ...runtime, host: sandboxHost(client(runtime), sandbox, { sleep: runtime.sandbox.sleep }) };
|
|
3637
|
+
}
|
|
3638
|
+
var SandboxGoneError = class extends Error {
|
|
3639
|
+
constructor(sandboxId, endedReason) {
|
|
3640
|
+
super(`The provider ended sandbox ${sandboxId} while the build ran${endedReason === void 0 || endedReason === "" ? "" : ` (${endedReason})`}`);
|
|
3641
|
+
this.endedReason = endedReason;
|
|
3642
|
+
this.name = "SandboxGoneError";
|
|
3643
|
+
}
|
|
3644
|
+
};
|
|
3645
|
+
async function inSandbox(runtime, state) {
|
|
3646
|
+
const sandbox = await sandboxOfBuild(runtime, state);
|
|
3647
|
+
if (sandbox === void 0) throw new SandboxGoneError(state.sandboxId);
|
|
3648
|
+
return runtimeInSandbox(runtime, sandbox);
|
|
3649
|
+
}
|
|
3650
|
+
async function goneReason(runtime, state) {
|
|
3651
|
+
try {
|
|
3652
|
+
const found = await client(runtime).get(state.sandboxId);
|
|
3653
|
+
return found.state === "ended" ? new SandboxGoneError(state.sandboxId, found.endedReason ?? void 0) : void 0;
|
|
3654
|
+
} catch (err) {
|
|
3655
|
+
return err instanceof SandboxError && err.status === 404 ? new SandboxGoneError(state.sandboxId) : void 0;
|
|
3656
|
+
}
|
|
3657
|
+
}
|
|
3658
|
+
function sandboxRunArgs(args) {
|
|
3659
|
+
const out = [...args];
|
|
3660
|
+
const network = out.indexOf("--network");
|
|
3661
|
+
if (network !== -1) out[network + 1] = "host";
|
|
3662
|
+
const entrypoint = out.indexOf("--entrypoint");
|
|
3663
|
+
out.splice(
|
|
3664
|
+
entrypoint,
|
|
3665
|
+
0,
|
|
3666
|
+
"--mount",
|
|
3667
|
+
`type=bind,src=${CLI_DIR},dst=/opt/outerlayer/cli/dist,readonly`,
|
|
3668
|
+
"--mount",
|
|
3669
|
+
`type=bind,src=${SECRET_FILE},dst=${CONTAINER_SECRET_FILE},readonly`,
|
|
3670
|
+
...Object.entries(toolProxyEnvironment()).flatMap(([name, value]) => ["--env", `${name}=${value}`])
|
|
3671
|
+
);
|
|
3672
|
+
out.push("--join-ws", String(JOIN_WS_PORT), "--join-secret-file", CONTAINER_SECRET_FILE);
|
|
3673
|
+
return out;
|
|
3674
|
+
}
|
|
3675
|
+
var RELAY_PROBE = `const s=require("net").connect(3128,"127.0.0.1");s.on("connect",()=>process.exit(0));s.on("error",()=>process.exit(1));setTimeout(()=>process.exit(1),2000)`;
|
|
3676
|
+
async function waitForRelay(runtime, container) {
|
|
3677
|
+
for (let attempt = 0; attempt < RELAY_ATTEMPTS; attempt++) {
|
|
3678
|
+
const probe = await runtime.host.exec({ container, user: RELAY_USER, env: NO_ENV, argv: ["/opt/outerlayer/bin/node", "-e", RELAY_PROBE] });
|
|
3679
|
+
if (probe.status === 0) return true;
|
|
3680
|
+
await runtime.sandbox.sleep(RELAY_WAIT_MS);
|
|
3681
|
+
}
|
|
3682
|
+
return false;
|
|
3683
|
+
}
|
|
3684
|
+
async function cleanupSandbox(runtime, state) {
|
|
3685
|
+
const failures = [];
|
|
3686
|
+
const relay = runtime.relays.get(state.buildId);
|
|
3687
|
+
if (relay !== void 0) {
|
|
3688
|
+
runtime.relays.delete(state.buildId);
|
|
3689
|
+
await relay.close();
|
|
3690
|
+
}
|
|
3691
|
+
runtime.relayFatal.delete(state.buildId);
|
|
3692
|
+
runtime.leases.get(state.buildId)?.close();
|
|
3693
|
+
runtime.leases.delete(state.buildId);
|
|
3694
|
+
if (state.sandboxId !== "") {
|
|
3695
|
+
try {
|
|
3696
|
+
await client(runtime).end(state.sandboxId);
|
|
3697
|
+
} catch (err) {
|
|
3698
|
+
failures.push(`sandbox ${state.sandboxId} was not ended: ${err instanceof SandboxError ? describeSandboxError(err) : describeCallFailure(err)}`);
|
|
3699
|
+
}
|
|
3700
|
+
}
|
|
3701
|
+
runtime.sandbox.sandboxes.delete(state.buildId);
|
|
3702
|
+
runtime.sandbox.joinSecrets.delete(state.buildId);
|
|
3703
|
+
const tunnel = runtime.tunnels.get(state.buildId);
|
|
3704
|
+
if (tunnel !== void 0) {
|
|
3705
|
+
runtime.tunnels.delete(state.buildId);
|
|
3706
|
+
await tunnel.close();
|
|
3707
|
+
}
|
|
3708
|
+
if (state.container !== void 0) rmSync(state.container.buildDir, { recursive: true, force: true });
|
|
3709
|
+
if (failures.length > 0) throw new Error(failures.join("; "));
|
|
3710
|
+
}
|
|
3711
|
+
async function provisionSandbox(input) {
|
|
3712
|
+
const { config, runtime, item, itemKey, jobDir, log, tokens } = input;
|
|
3713
|
+
const tag = itemTag({ item: item.number, organizationId: input.organizationId, claimId: input.claimId });
|
|
3714
|
+
const logPath = join(jobDir, "provision.log");
|
|
3715
|
+
const fail = (reason) => ({ ok: false, reason });
|
|
3716
|
+
const own = config.sandbox;
|
|
3717
|
+
if (own === void 0) return fail("runner.sandbox is not set in the config file");
|
|
3718
|
+
const repositories = repositoriesOf({ repositories: input.repositories, repository: item.specRepository, branch: input.branch });
|
|
3719
|
+
const primary = primaryOf(repositories);
|
|
3720
|
+
if (primary === void 0) return fail("the work item names no repository to clone");
|
|
3721
|
+
const repository = primary.repository;
|
|
3722
|
+
const sized = sandboxSizeOf(config.build);
|
|
3723
|
+
if (!sized.ok) return fail(`${sized.field} ${sized.problem}`);
|
|
3724
|
+
let sandboxClient;
|
|
3725
|
+
try {
|
|
3726
|
+
sandboxClient = client(runtime);
|
|
3727
|
+
} catch (err) {
|
|
3728
|
+
return fail(err instanceof SandboxError ? describeSandboxError(err) : describeCallFailure(err));
|
|
3729
|
+
}
|
|
3730
|
+
const governing = await resolveGoverningSource({ config, repository, fetchImpl: input.fetchImpl });
|
|
3731
|
+
if (!governing.ok) return fail(governing.reason);
|
|
3732
|
+
const governingSource = governing.source;
|
|
3733
|
+
const controlPlaneUrl = (controlPlane) => runtime.remoteFor?.(controlPlane) ?? `${runtime.github.gitUrl}/${controlPlane}.git`;
|
|
3734
|
+
if (governingSource.kind === "governed") {
|
|
3735
|
+
const unfetched = await prefetchGovernedContext({
|
|
3736
|
+
configPath: config.configPath,
|
|
3737
|
+
repository,
|
|
3738
|
+
source: governingSource,
|
|
3739
|
+
controlPlaneUrl,
|
|
3740
|
+
controlPlaneToken: () => tokens.controlPlane(),
|
|
3741
|
+
log,
|
|
3742
|
+
tag
|
|
3743
|
+
});
|
|
3744
|
+
if (unfetched !== void 0) return fail(unfetched);
|
|
3745
|
+
}
|
|
3746
|
+
const buildId = randomBytes(6).toString("hex");
|
|
3747
|
+
const runnerId = runnerLabelValue(config.configPath);
|
|
3748
|
+
const name = sandboxNameOf(runnerId, buildId);
|
|
3749
|
+
const container = `outerlayer-build-${buildId}`;
|
|
3750
|
+
const buildDir2 = buildDir(config.configPath, buildId);
|
|
3751
|
+
const image = own.image;
|
|
3752
|
+
const containerState = {
|
|
3753
|
+
buildId,
|
|
3754
|
+
container,
|
|
3755
|
+
volume: container,
|
|
3756
|
+
buildDir: buildDir2,
|
|
3757
|
+
repository,
|
|
3758
|
+
imageId: image,
|
|
3759
|
+
builtIns: true,
|
|
3760
|
+
...governingSource.kind === "governed" ? { governing: { repository: governingSource.repository, ref: governingSource.ref, commit: governingSource.sha } } : {},
|
|
3761
|
+
transport: "exec",
|
|
3762
|
+
jobFiles: "copied"
|
|
3763
|
+
};
|
|
3764
|
+
const state = { sandboxId: "", name, dataPlaneUrl: "", buildId, container: containerState };
|
|
3765
|
+
const secrets = secretsOf(runtime, jobDir);
|
|
3766
|
+
const env = buildEnvironment({
|
|
3767
|
+
config,
|
|
3768
|
+
item: item.number,
|
|
3769
|
+
itemKey,
|
|
3770
|
+
repository,
|
|
3771
|
+
repositories,
|
|
3772
|
+
hostEnv: runtime.hostEnv,
|
|
3773
|
+
agents: runtime.agents,
|
|
3774
|
+
...input.job === void 0 ? {} : { job: input.job },
|
|
3775
|
+
containerEnv: {},
|
|
3776
|
+
builtIns: true
|
|
3777
|
+
});
|
|
3778
|
+
if (env.skippedTokenVariables.length > 0) {
|
|
3779
|
+
log.line(`${tag} not passing ${env.skippedTokenVariables.join(", ")} from runner.build.variables into the build: its repository token comes from the runner`);
|
|
3780
|
+
}
|
|
3781
|
+
const environment = {
|
|
3782
|
+
isolation: "vm",
|
|
3783
|
+
imageId: image,
|
|
3784
|
+
variables: env.variables,
|
|
3785
|
+
cliVersion: input.cliVersion
|
|
3786
|
+
};
|
|
3787
|
+
const bail = async (reason, aborted2 = false) => {
|
|
3788
|
+
try {
|
|
3789
|
+
await cleanupSandbox(runtime, { buildId, sandboxId: state.sandboxId, container: containerState });
|
|
3790
|
+
} catch (err) {
|
|
3791
|
+
log.error(`${tag} cleanup failed: ${describeCallFailure(err)}`);
|
|
3792
|
+
}
|
|
3793
|
+
return aborted2 ? { ok: false, reason: "ended before provision finished", aborted: true } : fail(reason);
|
|
3794
|
+
};
|
|
3795
|
+
if (input.aborted()) return bail("", true);
|
|
3796
|
+
mkdirSync(buildDir2, { recursive: true });
|
|
3797
|
+
const ghDir = ghConfigDir(buildDir2);
|
|
3798
|
+
let readToken;
|
|
3799
|
+
try {
|
|
3800
|
+
readToken = await tokens.token("read");
|
|
3801
|
+
writeGhConfig(ghDir, readToken);
|
|
3802
|
+
} catch (err) {
|
|
3803
|
+
return bail(err instanceof WorkCommandError ? `the build's read token could not be had: ${refusalCode(err)}` : `the build's gh configuration could not be written: ${describeCallFailure(err)}`);
|
|
3804
|
+
}
|
|
3805
|
+
for (const entry of repositories) {
|
|
3806
|
+
if (entry.repository === primary.repository) continue;
|
|
3807
|
+
try {
|
|
3808
|
+
await tokens.token("read", entry.repository);
|
|
3809
|
+
} catch (err) {
|
|
3810
|
+
return bail(`the build's read token for ${entry.repository} could not be had: ${refusalCode(err)}`);
|
|
3811
|
+
}
|
|
3812
|
+
}
|
|
3813
|
+
keepGhConfigCurrent(tokens, buildDir2, (err) => log.error(`${tag} the read token could not be written for gh: ${describeCallFailure(err)}`));
|
|
3814
|
+
tokens.markUsed("read");
|
|
3815
|
+
environment.credentials = tokens.used();
|
|
3816
|
+
let services;
|
|
3817
|
+
try {
|
|
3818
|
+
const gitRemote = gitRemoteFor(runtime, { repositories, tokens, buildDir: buildDir2, log: (line2) => log.line(`${tag} ${line2}`) });
|
|
3819
|
+
services = await startServicesFor(runtime, config, buildDir2, jobDir, itemKey, true, gitRemote, "stream", input.leaseExpiryMs === void 0 ? void 0 : leaseFor(runtime, buildId, input.leaseExpiryMs), void 0, (line2) => log.line(`${tag} ${line2}`));
|
|
3820
|
+
runtime.tunnels.set(buildId, services);
|
|
3821
|
+
} catch (err) {
|
|
3822
|
+
return bail(`the tunnel could not start: ${describeCallFailure(err)}`);
|
|
3823
|
+
}
|
|
3824
|
+
if (input.aborted()) return bail("", true);
|
|
3825
|
+
let sandbox;
|
|
3826
|
+
runtime.sandbox.creating.add(buildId);
|
|
3827
|
+
try {
|
|
3828
|
+
sandbox = await sandboxClient.create({
|
|
3829
|
+
name,
|
|
3830
|
+
from: own.snapshot,
|
|
3831
|
+
...sized.size,
|
|
3832
|
+
idleMinutes: own.idleMinutes,
|
|
3833
|
+
timeLimitMinutes: sandboxTimeLimitMinutes(config.timeLimitMinutes),
|
|
3834
|
+
network: networkOf(own.allowHosts),
|
|
3835
|
+
metadata: { [RUNNER_METADATA]: runnerId, [BUILD_METADATA]: buildId }
|
|
3836
|
+
});
|
|
3837
|
+
} catch (err) {
|
|
3838
|
+
if (err instanceof SandboxError && err.status === 0) await endUnansweredSandbox(sandboxClient, runnerId, buildId, (line2) => log.error(`${tag} ${line2}`));
|
|
3839
|
+
runtime.sandbox.creating.delete(buildId);
|
|
3840
|
+
return bail(`The provider refused to create the sandbox: ${err instanceof SandboxError ? describeSandboxError(err) : describeCallFailure(err)}`);
|
|
3841
|
+
}
|
|
3842
|
+
runtime.sandbox.sandboxes.set(buildId, sandbox);
|
|
3843
|
+
state.sandboxId = sandbox.id;
|
|
3844
|
+
state.dataPlaneUrl = sandbox.dataPlaneUrl;
|
|
3845
|
+
input.save(state, environment);
|
|
3846
|
+
runtime.sandbox.creating.delete(buildId);
|
|
3847
|
+
log.line(`${tag} sandbox ${sandbox.id} created \xB7 ${name}`);
|
|
3848
|
+
if (input.aborted()) return bail("", true);
|
|
3849
|
+
const sandboxed = runtimeInSandbox(runtime, sandbox);
|
|
3850
|
+
const { host } = sandboxed;
|
|
3851
|
+
const dockerFailed = (what, result) => bail(`${what} failed (exit ${result.status})${said(result.stderr)}`);
|
|
3852
|
+
const joinSecret = randomBytes(32);
|
|
3853
|
+
runtime.sandbox.joinSecrets.set(buildId, joinSecret);
|
|
3854
|
+
try {
|
|
3855
|
+
await sandboxClient.command(sandbox, `mkdir -p ${CLI_DIR}`);
|
|
3856
|
+
await sandboxClient.upload(sandbox, `${SANDBOX_DIR}/dist.tgz`, gzipSync(packFolder(runtime.cliBuild().distDir)));
|
|
3857
|
+
await sandboxClient.upload(sandbox, SECRET_FILE, joinSecret);
|
|
3858
|
+
const unpacked = await sandboxClient.command(sandbox, `tar xzf ${SANDBOX_DIR}/dist.tgz -C ${CLI_DIR} && rm -f ${SANDBOX_DIR}/dist.tgz && sudo chown 60100:60100 ${SECRET_FILE} && sudo chmod 400 ${SECRET_FILE}`);
|
|
3859
|
+
if (unpacked.exitCode !== 0) return bail(`putting the CLI in the sandbox failed (exit ${unpacked.exitCode ?? "none"})${said(unpacked.stderr)}`);
|
|
3860
|
+
} catch (err) {
|
|
3861
|
+
return bail(`putting the CLI in the sandbox failed: ${err instanceof SandboxError ? describeSandboxError(err) : describeCallFailure(err)}`);
|
|
3862
|
+
}
|
|
3863
|
+
const engine = await host.version();
|
|
3864
|
+
if (engine === null) return bail("Docker is not available in the sandbox: `docker version` failed");
|
|
3865
|
+
const limits2 = { memory: `${Math.max(512, sized.size.memoryMib - SANDBOX_RESERVE_MIB)}m`, cpus: sized.size.vcpu, pids: config.build?.pids ?? 4096 };
|
|
3866
|
+
const volume = await host.createVolume(container, { [BUILD_LABEL]: buildId, [RUNNER_LABEL]: runnerId });
|
|
3867
|
+
if (volume.status !== 0) return dockerFailed("creating the build's volume", volume);
|
|
3868
|
+
const runInput = {
|
|
3869
|
+
buildId,
|
|
3870
|
+
runnerId,
|
|
3871
|
+
container,
|
|
3872
|
+
volume: container,
|
|
3873
|
+
image,
|
|
3874
|
+
user: ADDED_USER,
|
|
3875
|
+
limits: limits2,
|
|
3876
|
+
destinations: config.build?.destinations?.length ?? 0,
|
|
3877
|
+
builtIns: true,
|
|
3878
|
+
transport: "exec",
|
|
3879
|
+
jobFiles: "copied"
|
|
3880
|
+
};
|
|
3881
|
+
const prepared = await host.run(prepareRunArgs(runInput), { logPath });
|
|
3882
|
+
if (prepared.status !== 0) return dockerFailed("preparing the build's volume", prepared);
|
|
3883
|
+
const imageConfig = await host.imageConfig(image);
|
|
3884
|
+
const resolved = await resolveBuildUser(sandboxed, runInput, { imageUser: imageConfig.user }, logPath);
|
|
3885
|
+
if (!resolved.ok) return bail(resolved.reason);
|
|
3886
|
+
containerState.agentUser = resolved.user;
|
|
3887
|
+
if (resolved.home !== void 0) containerState.home = resolved.home;
|
|
3888
|
+
const agentUser = resolved.user;
|
|
3889
|
+
input.save(state, environment);
|
|
3890
|
+
if (input.aborted()) return bail("", true);
|
|
3891
|
+
const started = await host.run(sandboxRunArgs(containerRunArgs({ ...runInput, home: containerState.home }, runtime.agents)), { logPath });
|
|
3892
|
+
if (started.status !== 0) return dockerFailed("starting the build's container", started);
|
|
3893
|
+
const exec = sandboxExecStream({
|
|
3894
|
+
url: () => sandboxClient.portUrl(sandbox, JOIN_WS_PORT),
|
|
3895
|
+
secret: joinSecret,
|
|
3896
|
+
...runtime.sandbox.webSocket === void 0 ? {} : { webSocket: runtime.sandbox.webSocket }
|
|
3897
|
+
});
|
|
3898
|
+
runtime.relays.set(
|
|
3899
|
+
buildId,
|
|
3900
|
+
superviseRelay({
|
|
3901
|
+
container,
|
|
3902
|
+
services: services.streams,
|
|
3903
|
+
execStream: () => exec(),
|
|
3904
|
+
log: (line2) => log.line(`${tag} ${line2}`),
|
|
3905
|
+
onFatal: (reason) => runtime.relayFatal.set(buildId, reason),
|
|
3906
|
+
builtIns: builtInNames(runtime.agents)
|
|
3907
|
+
})
|
|
3908
|
+
);
|
|
3909
|
+
if (input.aborted()) return bail("", true);
|
|
3910
|
+
if (!await waitForRelay(sandboxed, container)) return bail("the relay in the build's container did not start");
|
|
3911
|
+
const ghDelivered = await deliverJobFiles(sandboxed, containerState, ["gh"], secrets);
|
|
3912
|
+
if (!ghDelivered.ok) return bail(ghDelivered.reason);
|
|
3913
|
+
keepGhConfigCurrent(tokens, buildDir2, (err) => log.error(`${tag} the read token could not be written for gh: ${describeCallFailure(err)}`), {
|
|
3914
|
+
runtime: sandboxed,
|
|
3915
|
+
state: containerState,
|
|
3916
|
+
secrets,
|
|
3917
|
+
delivered: readToken,
|
|
3918
|
+
onFailure: (reason) => log.error(`${tag} ${reason}`)
|
|
3919
|
+
});
|
|
3920
|
+
const tools = await host.exec({ container, user: ADDED_USER, env: NO_ENV, argv: ["cat", "/opt/outerlayer/tools.json"] });
|
|
3921
|
+
const agentVersion = agentVersionOf(tools.status === 0 ? tools.stdout : "", runtime.agents, input.job);
|
|
3922
|
+
environment.agentVersion = agentVersion;
|
|
3923
|
+
input.save(state, environment);
|
|
3924
|
+
const stepExec = async (argv, workdir, opts) => {
|
|
3925
|
+
const ran = await host.exec({ container, user: agentUser, workdir, env: withMiseVariables(env, opts?.variables), argv }, { ...opts?.quiet === true ? {} : { logPath }, ...opts?.timeoutMs === void 0 ? {} : { timeoutMs: opts.timeoutMs } });
|
|
3926
|
+
return endedAtLimit(ran) ? { ...ran, timedOut: true } : ran;
|
|
3927
|
+
};
|
|
3928
|
+
const setupMinutes = config.build?.setupMinutes ?? DEFAULT_SETUP_MINUTES;
|
|
3929
|
+
const steps = await runBuildSteps({
|
|
3930
|
+
repository,
|
|
3931
|
+
branch: primary.branch,
|
|
3932
|
+
repositories,
|
|
3933
|
+
...governingSource.kind === "governed" ? { governing: { repository: governingSource.repository } } : {},
|
|
3934
|
+
agentVersion,
|
|
3935
|
+
agents: runtime.agents,
|
|
3936
|
+
...input.job === void 0 ? {} : { job: input.job },
|
|
3937
|
+
lifecycle: {},
|
|
3938
|
+
exec: stepExec,
|
|
3939
|
+
log,
|
|
3940
|
+
tag,
|
|
3941
|
+
aborted: input.aborted,
|
|
3942
|
+
stageContext: () => stageGovernedContext({
|
|
3943
|
+
config,
|
|
3944
|
+
repository,
|
|
3945
|
+
source: pinnedSourceOf(governingSource),
|
|
3946
|
+
buildId,
|
|
3947
|
+
buildDir: buildDir2,
|
|
3948
|
+
fetchImpl: input.fetchImpl,
|
|
3949
|
+
controlPlaneUrl,
|
|
3950
|
+
controlPlaneToken: () => tokens.controlPlane(),
|
|
3951
|
+
log,
|
|
3952
|
+
tag
|
|
3953
|
+
}),
|
|
3954
|
+
deliverContext: async () => {
|
|
3955
|
+
const delivered = await deliverJobFiles(sandboxed, containerState, ["context"], secrets);
|
|
3956
|
+
return delivered.ok ? delivered : { ok: false, reason: `context_unavailable: ${delivered.reason}` };
|
|
3957
|
+
},
|
|
3958
|
+
removeStagedContext: () => removeStagedContext(buildDir2),
|
|
3959
|
+
keepIn: jobDir,
|
|
3960
|
+
...input.requireBuildSkill === true ? { requireBuildSkill: true } : {},
|
|
3961
|
+
// The image in the snapshot is the universal image, so the build chooses and installs its runtimes.
|
|
3962
|
+
...runtimeStepInput({ base: {} }, services),
|
|
3963
|
+
setup: { timeoutMs: setupMinutes * 6e4, limitMinutes: setupMinutes, restored: false }
|
|
3964
|
+
});
|
|
3965
|
+
if (!steps.ok) return steps.aborted === true ? bail("", true) : bail(steps.reason);
|
|
3966
|
+
containerState.startCommit = steps.startCommit;
|
|
3967
|
+
keepRuntimeStep(containerState, steps);
|
|
3968
|
+
keepMissingSetupScripts(containerState, steps);
|
|
3969
|
+
if (steps.controlPlane !== void 0) environment.controlPlane = steps.controlPlane;
|
|
3970
|
+
input.save(state, environment);
|
|
3971
|
+
return { ok: true, workdir: CHECKOUT_DIR, state, environment };
|
|
3972
|
+
}
|
|
3973
|
+
function asContainerJob(job) {
|
|
3974
|
+
return { ...job, container: job.sandbox.container };
|
|
3975
|
+
}
|
|
3976
|
+
async function deliverSandboxHooks(runtime, state, jobDir) {
|
|
3977
|
+
try {
|
|
3978
|
+
return await deliverJobFiles(await inSandbox(runtime, state), state.container, ["git-hooks"], secretsOf(runtime, jobDir));
|
|
3979
|
+
} catch (err) {
|
|
3980
|
+
return { ok: false, reason: `the commit hooks could not be delivered: ${describeCallFailure(err)}` };
|
|
3981
|
+
}
|
|
3982
|
+
}
|
|
3983
|
+
async function startSandboxCommand(input) {
|
|
3984
|
+
const own = input.job.sandbox;
|
|
3985
|
+
const runtime = await inSandbox(input.runtime, own);
|
|
3986
|
+
const exec = containerCommandExec({ job: asContainerJob(input.job), cmdline: input.cmdline, runtime, config: input.config, ...input.extraEnv === void 0 ? {} : { extraEnv: input.extraEnv } });
|
|
3987
|
+
const started = await runtime.host.execDetached(exec);
|
|
3988
|
+
if (started.status !== 0) {
|
|
3989
|
+
const first = started.stderr.trim().split("\n")[0] ?? "";
|
|
3990
|
+
throw new Error(`docker exec exited ${started.status}${first === "" ? "" : `: ${first}`}`);
|
|
3991
|
+
}
|
|
3992
|
+
}
|
|
3993
|
+
async function probeSandboxCommand(runtime, state, offset) {
|
|
3994
|
+
let sandboxed;
|
|
3995
|
+
try {
|
|
3996
|
+
sandboxed = await inSandbox(runtime, state);
|
|
3997
|
+
} catch (err) {
|
|
3998
|
+
if (err instanceof SandboxGoneError) throw await goneReason(runtime, state) ?? err;
|
|
3999
|
+
return void 0;
|
|
4000
|
+
}
|
|
4001
|
+
try {
|
|
4002
|
+
const result = await sandboxed.host.exec(
|
|
4003
|
+
{ container: state.container.container, user: state.container.agentUser ?? ADDED_USER, env: NO_ENV, argv: probeArgvOf(offset) },
|
|
4004
|
+
{ timeoutMs: 6e4 }
|
|
4005
|
+
);
|
|
4006
|
+
return result.status === 0 ? parseProbe(result.stdout) : void 0;
|
|
4007
|
+
} catch (err) {
|
|
4008
|
+
if (err instanceof SandboxError && err.status === 404) throw await goneReason(runtime, state) ?? new SandboxGoneError(state.sandboxId);
|
|
4009
|
+
if (err instanceof SandboxError) return void 0;
|
|
4010
|
+
throw err;
|
|
4011
|
+
}
|
|
4012
|
+
}
|
|
4013
|
+
function probeArgvOf(offset) {
|
|
4014
|
+
const argv = probeArgv(offset);
|
|
4015
|
+
argv[argv.length - 1] = String(SANDBOX_PROBE_BYTES);
|
|
4016
|
+
return argv;
|
|
4017
|
+
}
|
|
4018
|
+
async function endSandboxCommand(runtime, state, jobDir, warn) {
|
|
4019
|
+
try {
|
|
4020
|
+
const sandboxed = await inSandbox(runtime, state);
|
|
4021
|
+
for (let reads = 0; reads < MAX_TAIL_READS2; reads++) {
|
|
4022
|
+
const offset = commandLogOffset(jobDir, state.commandLogBase);
|
|
4023
|
+
const probe = await probeSandboxCommand(runtime, state, offset);
|
|
4024
|
+
if (probe === void 0) break;
|
|
4025
|
+
appendCommandLog(jobDir, probe.bytes);
|
|
4026
|
+
if (probe.bytes.length === 0 || offset + probe.bytes.length >= probe.size) break;
|
|
4027
|
+
}
|
|
4028
|
+
await sandboxed.host.stop(state.container.container);
|
|
4029
|
+
} catch (err) {
|
|
4030
|
+
warn(`ending the build's command in its sandbox failed: ${describeCallFailure(err)} \xB7 continuing`);
|
|
2951
4031
|
}
|
|
2952
|
-
|
|
2953
|
-
|
|
2954
|
-
|
|
2955
|
-
|
|
2956
|
-
|
|
2957
|
-
|
|
2958
|
-
|
|
2959
|
-
|
|
2960
|
-
|
|
4032
|
+
}
|
|
4033
|
+
async function runCliInSandbox(input, argv, logName) {
|
|
4034
|
+
const { job } = input;
|
|
4035
|
+
const own = job.sandbox;
|
|
4036
|
+
try {
|
|
4037
|
+
const sandboxed = await inSandbox(input.runtime, own);
|
|
4038
|
+
const state = own.container;
|
|
4039
|
+
const env = buildEnvironment({
|
|
4040
|
+
config: claimCalls(input.config, job),
|
|
4041
|
+
item: job.item,
|
|
4042
|
+
itemKey: job.itemKey,
|
|
4043
|
+
branch: job.branch,
|
|
4044
|
+
repository: state.repository,
|
|
4045
|
+
repositories: job.repositories,
|
|
4046
|
+
hostEnv: input.runtime.hostEnv,
|
|
4047
|
+
agents: input.runtime.agents,
|
|
4048
|
+
job,
|
|
4049
|
+
containerEnv: state.containerEnv ?? {},
|
|
4050
|
+
unpinnedRuntimes: state.unpinnedRuntimes,
|
|
4051
|
+
missingSetupScripts: state.missingSetupScripts,
|
|
4052
|
+
miseVariables: state.miseVariables,
|
|
4053
|
+
builtIns: true,
|
|
4054
|
+
identity: job.commitIdentity
|
|
4055
|
+
});
|
|
4056
|
+
const result = await sandboxed.host.exec(
|
|
4057
|
+
{ container: state.container, user: state.agentUser ?? ADDED_USER, workdir: job.workdir ?? CHECKOUT_DIR, env, argv },
|
|
4058
|
+
{ logPath: join(input.jobDir, logName) }
|
|
4059
|
+
);
|
|
4060
|
+
return result.status === 0 ? { ok: true } : { ok: false, reason: `exit ${result.status}` };
|
|
4061
|
+
} catch (err) {
|
|
4062
|
+
return { ok: false, reason: describeCallFailure(err) };
|
|
4063
|
+
}
|
|
4064
|
+
}
|
|
4065
|
+
function syncInSandbox(input) {
|
|
4066
|
+
return runCliInSandbox(input, ["outerlayer", "sync"], "sync.log");
|
|
4067
|
+
}
|
|
4068
|
+
function recordProofsInSandbox(input) {
|
|
4069
|
+
return runCliInSandbox(input, [...RECORD_PROOFS_ARGV], PROOFS_LOG);
|
|
2961
4070
|
}
|
|
2962
4071
|
function savedStatesDir(runnerDirPath) {
|
|
2963
4072
|
return join(runnerDirPath, "saved-states");
|
|
@@ -3471,168 +4580,6 @@ async function saveMicroVmDiskState(input) {
|
|
|
3471
4580
|
return discard(`the state could not be saved: ${describeCallFailure(err)}`);
|
|
3472
4581
|
}
|
|
3473
4582
|
}
|
|
3474
|
-
var FILE_MODE = 420;
|
|
3475
|
-
var DIR_MODE = 493;
|
|
3476
|
-
function replaceFile(path, text2) {
|
|
3477
|
-
const partial = `${path}.${process.pid}.partial`;
|
|
3478
|
-
writeFileSync(partial, text2);
|
|
3479
|
-
chmodSync(partial, FILE_MODE);
|
|
3480
|
-
renameSync(partial, path);
|
|
3481
|
-
}
|
|
3482
|
-
function ghHostsYml(token) {
|
|
3483
|
-
return [
|
|
3484
|
-
"github.com:",
|
|
3485
|
-
" users:",
|
|
3486
|
-
" x-access-token:",
|
|
3487
|
-
` oauth_token: ${token}`,
|
|
3488
|
-
` oauth_token: ${token}`,
|
|
3489
|
-
" user: x-access-token",
|
|
3490
|
-
" git_protocol: https",
|
|
3491
|
-
""
|
|
3492
|
-
].join("\n");
|
|
3493
|
-
}
|
|
3494
|
-
var GH_CONFIG_YML = 'version: "1"\n';
|
|
3495
|
-
function writeGhConfig(dir, token) {
|
|
3496
|
-
mkdirSync(dir, { recursive: true, mode: DIR_MODE });
|
|
3497
|
-
chmodSync(dir, DIR_MODE);
|
|
3498
|
-
replaceFile(join(dir, "hosts.yml"), ghHostsYml(token));
|
|
3499
|
-
replaceFile(join(dir, "config.yml"), GH_CONFIG_YML);
|
|
3500
|
-
}
|
|
3501
|
-
var DeliveryFailure = class extends Error {
|
|
3502
|
-
};
|
|
3503
|
-
var BLOCK2 = 512;
|
|
3504
|
-
var DELIVERY_TIMEOUT_MS = 5 * 6e4;
|
|
3505
|
-
var RECEIVE_ARGV = ["/opt/outerlayer/bin/node", "/opt/outerlayer/cli/dist/index.js", "receive-files"];
|
|
3506
|
-
var REASON_LINE_MAX = 240;
|
|
3507
|
-
var STEPS = {
|
|
3508
|
-
gh: "the build's gh configuration",
|
|
3509
|
-
"git-hooks": "the commit hooks",
|
|
3510
|
-
context: "the staged context",
|
|
3511
|
-
"eval-input": "the checks' input",
|
|
3512
|
-
inbox: "the comments for the agent"
|
|
3513
|
-
};
|
|
3514
|
-
function field(header, at, length, text2) {
|
|
3515
|
-
header.write(text2, at, length, "latin1");
|
|
3516
|
-
}
|
|
3517
|
-
function octalField(header, at, length, value) {
|
|
3518
|
-
field(header, at, length, `${value.toString(8).padStart(length - 1, "0")}\0`);
|
|
3519
|
-
}
|
|
3520
|
-
function tarHeader2(name, type, mode, size) {
|
|
3521
|
-
const header = Buffer.alloc(BLOCK2);
|
|
3522
|
-
header.write(name, 0, 100, "utf8");
|
|
3523
|
-
octalField(header, 100, 8, mode);
|
|
3524
|
-
octalField(header, 108, 8, 0);
|
|
3525
|
-
octalField(header, 116, 8, 0);
|
|
3526
|
-
octalField(header, 124, 12, size);
|
|
3527
|
-
octalField(header, 136, 12, 0);
|
|
3528
|
-
field(header, 148, 8, " ");
|
|
3529
|
-
header.write(type, 156, 1, "latin1");
|
|
3530
|
-
field(header, 257, 6, "ustar\0");
|
|
3531
|
-
field(header, 263, 2, "00");
|
|
3532
|
-
let sum = 0;
|
|
3533
|
-
for (const byte of header) sum += byte;
|
|
3534
|
-
field(header, 148, 8, `${sum.toString(8).padStart(6, "0")}\0 `);
|
|
3535
|
-
return header;
|
|
3536
|
-
}
|
|
3537
|
-
function padded(data) {
|
|
3538
|
-
const rest = data.length % BLOCK2;
|
|
3539
|
-
return rest === 0 ? data : Buffer.concat([data, Buffer.alloc(BLOCK2 - rest)]);
|
|
3540
|
-
}
|
|
3541
|
-
function paxRecord(key, value) {
|
|
3542
|
-
const body = Buffer.from(` ${key}=${value}
|
|
3543
|
-
`, "utf8");
|
|
3544
|
-
let length = body.length + 1;
|
|
3545
|
-
while (String(length).length + body.length !== length) length = String(length).length + body.length;
|
|
3546
|
-
return Buffer.concat([Buffer.from(String(length), "latin1"), body]);
|
|
3547
|
-
}
|
|
3548
|
-
function packTar(entries) {
|
|
3549
|
-
const blocks = [];
|
|
3550
|
-
for (const entry of entries) {
|
|
3551
|
-
const data = entry.type === "file" ? entry.data ?? Buffer.alloc(0) : Buffer.alloc(0);
|
|
3552
|
-
const name = entry.type === "dir" && !entry.path.endsWith("/") ? `${entry.path}/` : entry.path;
|
|
3553
|
-
if (Buffer.byteLength(name, "utf8") > 100) {
|
|
3554
|
-
const record = paxRecord("path", name);
|
|
3555
|
-
blocks.push(tarHeader2("PaxHeader", "x", 420, record.length), padded(record));
|
|
3556
|
-
}
|
|
3557
|
-
blocks.push(tarHeader2(name, entry.type === "dir" ? "5" : "0", entry.mode, data.length), padded(data));
|
|
3558
|
-
}
|
|
3559
|
-
blocks.push(Buffer.alloc(BLOCK2 * 2));
|
|
3560
|
-
return Buffer.concat(blocks);
|
|
3561
|
-
}
|
|
3562
|
-
function fileMode(hostMode) {
|
|
3563
|
-
return 292 | hostMode & 128 | ((hostMode & 73) === 0 ? 0 : 73);
|
|
3564
|
-
}
|
|
3565
|
-
function packFolder(dir, options = {}) {
|
|
3566
|
-
const entries = options.rootMode === void 0 ? [] : [{ path: "./", type: "dir", mode: options.rootMode }];
|
|
3567
|
-
const walk = (current, prefix) => {
|
|
3568
|
-
for (const name of readdirSync(current).sort()) {
|
|
3569
|
-
const path = join(current, name);
|
|
3570
|
-
const stat = lstatSync(path);
|
|
3571
|
-
const rel = prefix === "" ? name : `${prefix}/${name}`;
|
|
3572
|
-
if (stat.isDirectory()) {
|
|
3573
|
-
entries.push({ path: rel, type: "dir", mode: options.dirModes?.[rel] ?? 493 });
|
|
3574
|
-
walk(path, rel);
|
|
3575
|
-
} else if (stat.isFile()) {
|
|
3576
|
-
entries.push({ path: rel, type: "file", mode: fileMode(stat.mode), data: readFileSync(path) });
|
|
3577
|
-
}
|
|
3578
|
-
}
|
|
3579
|
-
};
|
|
3580
|
-
walk(dir, "");
|
|
3581
|
-
return packTar(entries);
|
|
3582
|
-
}
|
|
3583
|
-
function scrubDelivery(text2, secrets) {
|
|
3584
|
-
let out = text2.replace(/\u001b\[[0-?]*[ -/]*[@-~]/g, "").replace(/[\u0000-\u001f\u007f-\u009f]/g, " ");
|
|
3585
|
-
for (const secret of secrets()) if (secret !== "") out = out.split(secret).join("[redacted]");
|
|
3586
|
-
out = out.replace(/\b(?:gh[pousr]_|github_pat_)[A-Za-z0-9_]+/g, "[redacted]");
|
|
3587
|
-
out = out.trim();
|
|
3588
|
-
return out.length > REASON_LINE_MAX ? `${out.slice(0, REASON_LINE_MAX)}...` : out;
|
|
3589
|
-
}
|
|
3590
|
-
async function deliverTar(runtime, state, input) {
|
|
3591
|
-
try {
|
|
3592
|
-
const result = await runtime.host.exec(
|
|
3593
|
-
{
|
|
3594
|
-
container: state.container,
|
|
3595
|
-
user: RELAY_USER,
|
|
3596
|
-
env: { literals: {}, passed: {} },
|
|
3597
|
-
argv: [...RECEIVE_ARGV, "--into", input.into, ...input.replace === true ? ["--replace"] : []],
|
|
3598
|
-
stdin: input.tar
|
|
3599
|
-
},
|
|
3600
|
-
{ timeoutMs: DELIVERY_TIMEOUT_MS }
|
|
3601
|
-
);
|
|
3602
|
-
if (result.status === 0) return { ok: true };
|
|
3603
|
-
const line2 = scrubDelivery(result.stderr.trim().split("\n")[0] ?? "", input.secrets);
|
|
3604
|
-
return { ok: false, reason: `${input.step} could not be delivered (exit ${result.status})${line2 === "" ? "" : `: ${line2}`}` };
|
|
3605
|
-
} catch (err) {
|
|
3606
|
-
return { ok: false, reason: `${input.step} could not be delivered: ${scrubDelivery(describeCallFailure(err), input.secrets)}` };
|
|
3607
|
-
}
|
|
3608
|
-
}
|
|
3609
|
-
async function deliverJobFiles(runtime, state, parts, secrets) {
|
|
3610
|
-
for (const part of parts) {
|
|
3611
|
-
const dir = join(state.buildDir, part === "eval-input" ? EVAL_INPUT_NAME : part);
|
|
3612
|
-
if (!existsSync(dir)) continue;
|
|
3613
|
-
let tar;
|
|
3614
|
-
try {
|
|
3615
|
-
tar = packFolder(dir);
|
|
3616
|
-
} catch (err) {
|
|
3617
|
-
return { ok: false, reason: `${STEPS[part]} could not be read on the host: ${scrubDelivery(describeCallFailure(err), secrets)}` };
|
|
3618
|
-
}
|
|
3619
|
-
const delivered = await deliverTar(runtime, state, { step: STEPS[part], tar, into: `${JOB_MOUNT}/${part}`, replace: part === "eval-input", secrets });
|
|
3620
|
-
if (!delivered.ok) return delivered;
|
|
3621
|
-
}
|
|
3622
|
-
return { ok: true };
|
|
3623
|
-
}
|
|
3624
|
-
function deliverGhConfig(runtime, state, secrets) {
|
|
3625
|
-
return deliverJobFiles(runtime, state, ["gh"], secrets);
|
|
3626
|
-
}
|
|
3627
|
-
function deliverEvalInput(runtime, state, secrets) {
|
|
3628
|
-
return deliverJobFiles(runtime, state, ["eval-input"], secrets);
|
|
3629
|
-
}
|
|
3630
|
-
async function deliverJudgeInputs(runtime, state, dir, secrets) {
|
|
3631
|
-
return deliverTar(runtime, state, { step: "the judge's inputs", tar: packFolder(dir, { rootMode: 1023, dirModes: { home: 511, "home/tmp": 511 } }), into: JUDGE_DIR, replace: true, secrets });
|
|
3632
|
-
}
|
|
3633
|
-
function clearJudgeFolder(runtime, state, secrets) {
|
|
3634
|
-
return deliverTar(runtime, state, { step: "clearing the judge's folder", tar: packTar([]), into: JUDGE_DIR, replace: true, secrets });
|
|
3635
|
-
}
|
|
3636
4583
|
async function serveLease(socketPath, channel, makeServer = createServer, listenOn) {
|
|
3637
4584
|
const server = makeServer((socket) => channel.accept(socket));
|
|
3638
4585
|
if (listenOn === void 0) {
|
|
@@ -3688,9 +4635,9 @@ async function probeMicroVmCommand(runtime, state, offset) {
|
|
|
3688
4635
|
return void 0;
|
|
3689
4636
|
}
|
|
3690
4637
|
}
|
|
3691
|
-
var
|
|
4638
|
+
var MAX_TAIL_READS3 = 8;
|
|
3692
4639
|
async function copyMicroVmLogTail(runtime, state, jobDir) {
|
|
3693
|
-
for (let reads = 0; reads <
|
|
4640
|
+
for (let reads = 0; reads < MAX_TAIL_READS3; reads++) {
|
|
3694
4641
|
const offset = commandLogOffset(jobDir, state.commandLogBase);
|
|
3695
4642
|
const probe = await probeMicroVmCommand(runtime, state, offset);
|
|
3696
4643
|
if (probe === void 0) return false;
|
|
@@ -3786,10 +4733,6 @@ function copyJudgeTree(from, to, limits2 = { files: MAX_TREE_FILES, bytes: MAX_T
|
|
|
3786
4733
|
walk(from, to, true);
|
|
3787
4734
|
}
|
|
3788
4735
|
|
|
3789
|
-
// src/runner/record-proofs.ts
|
|
3790
|
-
var RECORD_PROOFS_ARGV = ["outerlayer", "work", "proofs", "--record", "--comment"];
|
|
3791
|
-
var PROOFS_LOG = "proofs.log";
|
|
3792
|
-
|
|
3793
4736
|
// src/runner/microvm/hooks.ts
|
|
3794
4737
|
var MANAGED_NO_BUILDER_DISK_REASON = "this release of the CLI pins no builder root disk, and a managed runner builds its images in a builder microVM, never on the host. The build did not start; update the CLI";
|
|
3795
4738
|
var DEFAULT_MEMORY = "8g";
|
|
@@ -4567,10 +5510,10 @@ async function syncInMicroVm(input) {
|
|
|
4567
5510
|
async function recordProofsInMicroVm(input) {
|
|
4568
5511
|
return runCliInMicroVm(input, [...RECORD_PROOFS_ARGV], PROOFS_LOG, "the microVM is gone, so its proofs cannot be recorded");
|
|
4569
5512
|
}
|
|
4570
|
-
async function runCliInMicroVm(input, argv, logName,
|
|
5513
|
+
async function runCliInMicroVm(input, argv, logName, goneReason2) {
|
|
4571
5514
|
const { runtime, job } = input;
|
|
4572
5515
|
const state = job.microvm;
|
|
4573
|
-
if (!isRunning(runtime, state)) return { ok: false, reason:
|
|
5516
|
+
if (!isRunning(runtime, state)) return { ok: false, reason: goneReason2 };
|
|
4574
5517
|
try {
|
|
4575
5518
|
const env = buildEnvironment({
|
|
4576
5519
|
config: claimCalls(input.config, job),
|
|
@@ -5214,15 +6157,15 @@ function createDecryptor(deps) {
|
|
|
5214
6157
|
server.on("clientError", (_err, socket) => socket.destroy());
|
|
5215
6158
|
return {
|
|
5216
6159
|
matches: (host, port) => variablesFor(decrypt.variables(), host, port).length > 0,
|
|
5217
|
-
accept(
|
|
6160
|
+
accept(client2, head, target2) {
|
|
5218
6161
|
const host = target2.host.toLowerCase();
|
|
5219
6162
|
const leaf = decrypt.authority.leafFor(host);
|
|
5220
|
-
let carrier =
|
|
6163
|
+
let carrier = client2;
|
|
5221
6164
|
if (head.length > 0) {
|
|
5222
6165
|
const inbound = new PassThrough();
|
|
5223
6166
|
inbound.write(head);
|
|
5224
|
-
|
|
5225
|
-
carrier = Duplex.from({ readable: inbound, writable:
|
|
6167
|
+
client2.pipe(inbound);
|
|
6168
|
+
carrier = Duplex.from({ readable: inbound, writable: client2 });
|
|
5226
6169
|
}
|
|
5227
6170
|
const tls = new TLSSocket(carrier, { isServer: true, secureContext: createSecureContext({ key: leaf.keyPem, cert: leaf.certPem }), ALPNProtocols: ["http/1.1"] });
|
|
5228
6171
|
const agent = new Agent({ keepAlive: true, maxSockets: MAX_UPSTREAM_SOCKETS });
|
|
@@ -5251,7 +6194,7 @@ function createDecryptor(deps) {
|
|
|
5251
6194
|
tls.once("close", () => {
|
|
5252
6195
|
open.delete(tls);
|
|
5253
6196
|
agent.destroy();
|
|
5254
|
-
|
|
6197
|
+
client2.destroy();
|
|
5255
6198
|
});
|
|
5256
6199
|
server.emit("connection", tls);
|
|
5257
6200
|
},
|
|
@@ -5564,41 +6507,41 @@ async function startTunnel(socketPath, opts = {}) {
|
|
|
5564
6507
|
sockets.add(socket);
|
|
5565
6508
|
socket.on("close", () => sockets.delete(socket));
|
|
5566
6509
|
});
|
|
5567
|
-
server.on("connect", (req,
|
|
5568
|
-
void tunnelConnect(req,
|
|
6510
|
+
server.on("connect", (req, client2, head) => {
|
|
6511
|
+
void tunnelConnect(req, client2, head);
|
|
5569
6512
|
});
|
|
5570
6513
|
const statusLine = (status) => `HTTP/1.1 ${status} ${status === 403 ? "Forbidden" : status === 429 ? "Too Many Requests" : "Bad Gateway"}`;
|
|
5571
|
-
const reply = (
|
|
5572
|
-
|
|
6514
|
+
const reply = (client2, status, body) => {
|
|
6515
|
+
client2.end(`${statusLine(status)}\r
|
|
5573
6516
|
Content-Type: text/plain\r
|
|
5574
6517
|
Content-Length: ${Buffer.byteLength(body)}\r
|
|
5575
6518
|
Connection: close\r
|
|
5576
6519
|
\r
|
|
5577
6520
|
${body}`);
|
|
5578
6521
|
};
|
|
5579
|
-
async function tunnelConnect(req,
|
|
5580
|
-
|
|
6522
|
+
async function tunnelConnect(req, client2, head) {
|
|
6523
|
+
client2.on("error", () => client2.destroy());
|
|
5581
6524
|
const target2 = parseTarget(req.url ?? "");
|
|
5582
6525
|
if (target2 === void 0) {
|
|
5583
|
-
|
|
6526
|
+
client2.end("HTTP/1.1 400 Bad Request\r\nConnection: close\r\nContent-Length: 0\r\n\r\n");
|
|
5584
6527
|
return;
|
|
5585
6528
|
}
|
|
5586
6529
|
const over = admit();
|
|
5587
6530
|
if (over !== void 0) {
|
|
5588
6531
|
const refusal = refuseOverLimit(target2.host, over);
|
|
5589
|
-
reply(
|
|
6532
|
+
reply(client2, refusal.status, refusal.body);
|
|
5590
6533
|
return;
|
|
5591
6534
|
}
|
|
5592
|
-
|
|
6535
|
+
client2.once("close", release);
|
|
5593
6536
|
const decision = await decide(target2.host, target2.port);
|
|
5594
6537
|
if (!decision.ok) {
|
|
5595
|
-
reply(
|
|
6538
|
+
reply(client2, decision.status, decision.body);
|
|
5596
6539
|
return;
|
|
5597
6540
|
}
|
|
5598
6541
|
if (decryptor?.matches(target2.host, target2.port) === true) {
|
|
5599
6542
|
reached(target2.host);
|
|
5600
|
-
|
|
5601
|
-
decryptor.accept(
|
|
6543
|
+
client2.write("HTTP/1.1 200 Connection Established\r\n\r\n");
|
|
6544
|
+
decryptor.accept(client2, head, { host: target2.host, port: target2.port, address: decision.address });
|
|
5602
6545
|
return;
|
|
5603
6546
|
}
|
|
5604
6547
|
const upstream = openConnection({ address: decision.address, port: target2.port });
|
|
@@ -5606,54 +6549,54 @@ ${body}`);
|
|
|
5606
6549
|
const failed = (err) => {
|
|
5607
6550
|
upstream.destroy();
|
|
5608
6551
|
logBadGateway(`could not connect to ${target2.host}:${target2.port}, ${err === void 0 ? "ETIMEDOUT" : errorCode(err)}`);
|
|
5609
|
-
reply(
|
|
6552
|
+
reply(client2, 502, `could not connect to ${target2.host}
|
|
5610
6553
|
`);
|
|
5611
6554
|
};
|
|
5612
6555
|
const timedOut = () => failed();
|
|
5613
6556
|
upstream.once("error", failed);
|
|
5614
6557
|
upstream.once("timeout", timedOut);
|
|
5615
|
-
|
|
6558
|
+
client2.on("close", () => upstream.destroy());
|
|
5616
6559
|
const established = () => {
|
|
5617
6560
|
upstream.removeListener("error", failed);
|
|
5618
6561
|
upstream.removeListener("timeout", timedOut);
|
|
5619
6562
|
upstream.setTimeout(idleTimeoutMs, () => upstream.destroy());
|
|
5620
|
-
upstream.on("error", (err) =>
|
|
6563
|
+
upstream.on("error", (err) => client2.destroy(err));
|
|
5621
6564
|
upstream.on("close", () => {
|
|
5622
|
-
if (!upstream.readableEnded && !
|
|
5623
|
-
else
|
|
6565
|
+
if (!upstream.readableEnded && !client2.writableEnded) client2.destroy(abortedError("the tunnel closed the connection to the server before it ended"));
|
|
6566
|
+
else client2.resume();
|
|
5624
6567
|
});
|
|
5625
6568
|
const buildEnded = () => {
|
|
5626
6569
|
upstream.destroy();
|
|
5627
|
-
|
|
6570
|
+
client2.end();
|
|
5628
6571
|
};
|
|
5629
6572
|
const metered = limits2.sendBytesPerSecond > 0 ? meter() : void 0;
|
|
5630
|
-
if (metered === void 0)
|
|
6573
|
+
if (metered === void 0) client2.once("end", buildEnded);
|
|
5631
6574
|
else metered.once("end", buildEnded);
|
|
5632
6575
|
reached(target2.host);
|
|
5633
|
-
|
|
6576
|
+
client2.write("HTTP/1.1 200 Connection Established\r\n\r\n");
|
|
5634
6577
|
if (metered !== void 0) {
|
|
5635
6578
|
if (head.length > 0) metered.write(head);
|
|
5636
6579
|
} else {
|
|
5637
6580
|
counts.bytesSent += head.length;
|
|
5638
6581
|
upstream.write(head);
|
|
5639
6582
|
}
|
|
5640
|
-
releaseWhenStalled(
|
|
5641
|
-
upstream.pipe(
|
|
6583
|
+
releaseWhenStalled(client2, upstream);
|
|
6584
|
+
upstream.pipe(client2);
|
|
5642
6585
|
if (metered === void 0) {
|
|
5643
|
-
|
|
6586
|
+
client2.on("data", (chunk) => {
|
|
5644
6587
|
counts.bytesSent += chunk.length;
|
|
5645
6588
|
persistSoon();
|
|
5646
6589
|
});
|
|
5647
|
-
|
|
6590
|
+
client2.pipe(upstream);
|
|
5648
6591
|
} else {
|
|
5649
|
-
|
|
5650
|
-
|
|
6592
|
+
client2.once("close", () => metered.destroy());
|
|
6593
|
+
client2.pipe(metered).pipe(upstream);
|
|
5651
6594
|
}
|
|
5652
6595
|
};
|
|
5653
6596
|
if (upstream.readyState === "open") established();
|
|
5654
6597
|
else upstream.once("connect", established);
|
|
5655
6598
|
}
|
|
5656
|
-
function releaseWhenStalled(
|
|
6599
|
+
function releaseWhenStalled(client2, upstream) {
|
|
5657
6600
|
let delivered = 0;
|
|
5658
6601
|
upstream.on("data", (chunk) => delivered += chunk.length);
|
|
5659
6602
|
let read = delivered;
|
|
@@ -5661,13 +6604,13 @@ ${body}`);
|
|
|
5661
6604
|
const blocked = () => upstream.isPaused() || upstream.readableEnded;
|
|
5662
6605
|
const check = () => {
|
|
5663
6606
|
timer = void 0;
|
|
5664
|
-
if (
|
|
6607
|
+
if (client2.writableFinished || !blocked()) return;
|
|
5665
6608
|
if (delivered > read) {
|
|
5666
6609
|
read = delivered;
|
|
5667
6610
|
timer = setTimeout(check, stalledResponseMs);
|
|
5668
6611
|
return;
|
|
5669
6612
|
}
|
|
5670
|
-
|
|
6613
|
+
client2.destroy(abortedError("the build stopped reading the response"));
|
|
5671
6614
|
};
|
|
5672
6615
|
let clientClosed = false;
|
|
5673
6616
|
const watch = () => {
|
|
@@ -5677,7 +6620,7 @@ ${body}`);
|
|
|
5677
6620
|
};
|
|
5678
6621
|
upstream.on("pause", watch);
|
|
5679
6622
|
upstream.on("end", watch);
|
|
5680
|
-
|
|
6623
|
+
client2.once("close", () => {
|
|
5681
6624
|
clientClosed = true;
|
|
5682
6625
|
clearTimeout(timer);
|
|
5683
6626
|
});
|
|
@@ -6075,6 +7018,7 @@ async function startSender(input) {
|
|
|
6075
7018
|
const { config, job, jobDir, deps } = input;
|
|
6076
7019
|
const tag = `${itemTag(job)}`;
|
|
6077
7020
|
if (job.itemKey === void 0) return void 0;
|
|
7021
|
+
if (job.sandbox !== void 0) return void 0;
|
|
6078
7022
|
const spawnFn = deps.spawnFn ?? spawn;
|
|
6079
7023
|
try {
|
|
6080
7024
|
const launch = launchFor(config, job, jobDir, deps);
|
|
@@ -6752,7 +7696,7 @@ ${input.extraHead ?? ""}
|
|
|
6752
7696
|
<p>${escape(summary)}.${input.reason === void 0 ? "" : ` ${escape(input.reason)}.`}</p>
|
|
6753
7697
|
<p class="meta">Judged at commit <code>${escape(input.commit)}</code>.</p>
|
|
6754
7698
|
<table>
|
|
6755
|
-
<thead><tr><th>Item</th><th>Result</th><th>Reason</th><th>
|
|
7699
|
+
<thead><tr><th>Item</th><th>Result</th><th>Reason</th><th>Where</th></tr></thead>
|
|
6756
7700
|
<tbody>
|
|
6757
7701
|
${rows}
|
|
6758
7702
|
</tbody>
|
|
@@ -6767,6 +7711,16 @@ var LIMIT_KEY_TAIL = " (runner.checks.timeLimitMinutes)";
|
|
|
6767
7711
|
var MAX_DIFF_BYTES = 4 * 1024 * 1024;
|
|
6768
7712
|
var noAgentProgram = (label) => `the image has no ${label} for the judge`;
|
|
6769
7713
|
var REPORT_CAPTION = "The host's criteria judge, each criterion judged against the tests that prove it";
|
|
7714
|
+
var WHOLE_REPORT_CAPTION = "The host's judge of the change as a whole";
|
|
7715
|
+
var CODE_REVIEW_BRIEF = "code-review-judge.md";
|
|
7716
|
+
function codeReviewCheck() {
|
|
7717
|
+
let text2;
|
|
7718
|
+
try {
|
|
7719
|
+
text2 = readFileSync(join(resolvePackRoot(), "maintained", "outerlayer-build", "references", CODE_REVIEW_BRIEF), "utf8");
|
|
7720
|
+
} catch {
|
|
7721
|
+
}
|
|
7722
|
+
return { name: CODE_REVIEW_NAME, builtIn: true, judge: { brief: CODE_REVIEW_BRIEF, text: text2, subjects: "none" } };
|
|
7723
|
+
}
|
|
6770
7724
|
function treeFileText(root, path) {
|
|
6771
7725
|
const segments = path.split("/");
|
|
6772
7726
|
if (segments.some((segment) => segment === "" || segment === "." || segment === "..")) return void 0;
|
|
@@ -6794,23 +7748,33 @@ function proofsFileIn(root) {
|
|
|
6794
7748
|
return void 0;
|
|
6795
7749
|
}
|
|
6796
7750
|
}
|
|
6797
|
-
async function
|
|
6798
|
-
const workItemId = Object(
|
|
7751
|
+
async function* resultsOf(config, workItem, fetchImpl) {
|
|
7752
|
+
const workItemId = Object(workItem).workItemId;
|
|
6799
7753
|
if (typeof workItemId !== "string") throw new WorkCommandError("the work item read named no id");
|
|
6800
7754
|
const signer = await signerFor(config.configPath);
|
|
6801
|
-
const latest = /* @__PURE__ */ new Map();
|
|
6802
7755
|
let since = null;
|
|
6803
7756
|
do {
|
|
6804
7757
|
const query = since === null ? "" : `?since=${encodeURIComponent(since)}`;
|
|
6805
7758
|
const page = await getJson(config.url, `/v1/work-items/${encodeURIComponent(workItemId)}/changes${query}`, config.apiKey, config.appId, fetchImpl, signer);
|
|
6806
|
-
for (const entry of Array.isArray(page.data) ? page.data : [])
|
|
6807
|
-
const { name, result, source } = Object(entry);
|
|
6808
|
-
if (source === "host" && typeof name === "string" && typeof result === "string") latest.set(name, result);
|
|
6809
|
-
}
|
|
7759
|
+
for (const entry of Array.isArray(page.data) ? page.data : []) yield Object(entry);
|
|
6810
7760
|
since = page.pagination?.cursor ?? null;
|
|
6811
7761
|
} while (since !== null);
|
|
7762
|
+
}
|
|
7763
|
+
async function hostPassedNames(config, item, fetchImpl) {
|
|
7764
|
+
const latest = /* @__PURE__ */ new Map();
|
|
7765
|
+
for await (const { name, result, source } of resultsOf(config, await readWorkItem(config, item, fetchImpl), fetchImpl)) {
|
|
7766
|
+
if (source === "host" && typeof name === "string" && name !== CODE_REVIEW_NAME && typeof result === "string") latest.set(name, result);
|
|
7767
|
+
}
|
|
6812
7768
|
return [...latest].filter(([, result]) => result === "pass").map(([name]) => name);
|
|
6813
7769
|
}
|
|
7770
|
+
async function hostReviewed(config, workItem, commit, fetchImpl) {
|
|
7771
|
+
for await (const { name, source, items } of resultsOf(config, workItem, fetchImpl)) {
|
|
7772
|
+
if (name !== CODE_REVIEW_NAME || source !== "host" || !Array.isArray(items)) continue;
|
|
7773
|
+
const parts = items.map((item) => Object(item));
|
|
7774
|
+
if (parts.some((part) => part.commit === commit) && !parts.some((part) => part.id === JUDGE_NOT_RUN_ITEM_ID)) return true;
|
|
7775
|
+
}
|
|
7776
|
+
return false;
|
|
7777
|
+
}
|
|
6814
7778
|
function environmentFor(input) {
|
|
6815
7779
|
const { config, job, jobDir, deps } = input;
|
|
6816
7780
|
if (deps.judgeEnvironment !== void 0) return deps.judgeEnvironment;
|
|
@@ -6826,11 +7790,14 @@ async function runJudge(input) {
|
|
|
6826
7790
|
const repository = job.repository ?? job.container?.repository;
|
|
6827
7791
|
if (repository === void 0) return;
|
|
6828
7792
|
const repo = repository;
|
|
7793
|
+
const remoteOf = () => runtime.remoteFor?.(repo) ?? `${runtime.github.gitUrl}/${repo}.git`;
|
|
6829
7794
|
let itemRead;
|
|
6830
7795
|
const readItem = () => itemRead ??= readWorkItem(itemCalls(config, job), job.item, deps.fetchImpl).catch((err) => {
|
|
6831
7796
|
itemRead = void 0;
|
|
6832
7797
|
throw err;
|
|
6833
7798
|
});
|
|
7799
|
+
const cleanReason = (text2) => scrubReason(text2, config, void 0, jobDir, CHECK_ITEM_REASON_MAX_LENGTH) ?? "";
|
|
7800
|
+
const notRunItems = (reason) => [{ id: JUDGE_NOT_RUN_ITEM_ID, result: "fail", reason: oneLineReason(cleanReason(reason)) ?? "the judge did not run" }];
|
|
6834
7801
|
const tokens = runtime.credentials.get(jobDir);
|
|
6835
7802
|
let readToken;
|
|
6836
7803
|
try {
|
|
@@ -6850,23 +7817,25 @@ async function runJudge(input) {
|
|
|
6850
7817
|
} finally {
|
|
6851
7818
|
removeStagedContext(definitionsDir);
|
|
6852
7819
|
}
|
|
6853
|
-
|
|
6854
|
-
|
|
7820
|
+
let checks = [];
|
|
7821
|
+
if (definitions.ok) {
|
|
7822
|
+
for (const id of definitions.unrecorded) {
|
|
7823
|
+
log.line(`${tag} judge not run for ${id}: the check is not run.where: host with a judge or a command, so this host records no result for it`);
|
|
7824
|
+
}
|
|
7825
|
+
checks = definitions.checks.filter(isJudgeCheck);
|
|
7826
|
+
} else {
|
|
6855
7827
|
log.line(`${tag} judge not run: the definitions could not be read: ${definitions.reason}`);
|
|
6856
7828
|
job.judgeNotRun = `the definitions could not be read: ${definitions.reason}`;
|
|
6857
7829
|
const passed = await retrySend(() => hostPassedNames(itemCalls(config, job), job.item, deps.fetchImpl), { now: deps.now });
|
|
6858
|
-
if (
|
|
7830
|
+
if (passed.ok) {
|
|
7831
|
+
const record2 = makeRecorder({ config, job, jobDir, deps });
|
|
7832
|
+
const reason = `the definitions could not be read: ${definitions.reason}`;
|
|
7833
|
+
for (const name of passed.value) await record2(name, "fail", reason, { idTag: "judge-unread", ...name === CRITERIA_CHECK ? {} : { items: notRunItems(reason) } });
|
|
7834
|
+
} else {
|
|
6859
7835
|
log.error(`${tag} the item's host results could not be read, so none was failed: ${passed.reason}`);
|
|
6860
|
-
return;
|
|
6861
7836
|
}
|
|
6862
|
-
const record2 = makeRecorder({ config, job, jobDir, deps });
|
|
6863
|
-
for (const name of passed.value) await record2(name, "fail", `the definitions could not be read: ${definitions.reason}`, { idTag: "judge-unread" });
|
|
6864
|
-
return;
|
|
6865
|
-
}
|
|
6866
|
-
for (const id of definitions.unrecorded) {
|
|
6867
|
-
log.line(`${tag} judge not run for ${id}: the check is not run.where: host with a judge or a command, so this host records no result for it`);
|
|
6868
7837
|
}
|
|
6869
|
-
|
|
7838
|
+
if (job.codeReview === true) checks = [...checks, codeReviewCheck()];
|
|
6870
7839
|
if (checks.length === 0) {
|
|
6871
7840
|
rmSync(scratch, { recursive: true, force: true });
|
|
6872
7841
|
return;
|
|
@@ -6876,7 +7845,7 @@ async function runJudge(input) {
|
|
|
6876
7845
|
const record = makeRecorder({ config, job, jobDir, deps });
|
|
6877
7846
|
const fail = (check, reason) => {
|
|
6878
7847
|
log.error(`${tag} judge failed: ${reason}`);
|
|
6879
|
-
return record(check.name, "fail", reason);
|
|
7848
|
+
return record(check.name, "fail", reason, check.judge.subjects === "none" ? { items: notRunItems(reason) } : {});
|
|
6880
7849
|
};
|
|
6881
7850
|
try {
|
|
6882
7851
|
for (const check of checks) {
|
|
@@ -6890,7 +7859,37 @@ async function runJudge(input) {
|
|
|
6890
7859
|
rmSync(scratch, { recursive: true, force: true });
|
|
6891
7860
|
log.line(`${tag} judge done (${formatDuration(now().getTime() - startedMs)})`);
|
|
6892
7861
|
}
|
|
7862
|
+
async function noReview() {
|
|
7863
|
+
const started = job.container ?? job.microvm;
|
|
7864
|
+
if (started === void 0) return "this build ran under a provision hook of the host's own";
|
|
7865
|
+
const workItem = await readItem();
|
|
7866
|
+
const open = openPullRequests(workItem);
|
|
7867
|
+
if (open.length > 1) return "the item has more than one open pull request";
|
|
7868
|
+
if (open.length === 1 && open[0].toLowerCase() !== repo.toLowerCase()) return "the item's open pull request is in another repository";
|
|
7869
|
+
if (job.branch === void 0) return void 0;
|
|
7870
|
+
const read = await (deps.readBranch ?? readBranchHead)({ remote: remoteOf(), dir: scratch, branch: job.branch, token: readToken });
|
|
7871
|
+
if (read.kind === "unreadable") return void 0;
|
|
7872
|
+
if (read.kind === "absent" || read.sha === started.startCommit) return "the branch holds nothing to review";
|
|
7873
|
+
try {
|
|
7874
|
+
return await hostReviewed(itemCalls(config, job), workItem, read.sha, deps.fetchImpl) ? "a host result already covers the branch head" : void 0;
|
|
7875
|
+
} catch (err) {
|
|
7876
|
+
log.line(`${tag} the item's results could not be read, so the head is reviewed: ${describeCallFailure(err)}`);
|
|
7877
|
+
return void 0;
|
|
7878
|
+
}
|
|
7879
|
+
}
|
|
6893
7880
|
async function judgeOne(check) {
|
|
7881
|
+
if (check.builtIn === true) {
|
|
7882
|
+
let skipped;
|
|
7883
|
+
try {
|
|
7884
|
+
skipped = await noReview();
|
|
7885
|
+
} catch (err) {
|
|
7886
|
+
return await fail(check, `the item could not be read: ${describeCallFailure(err)}`);
|
|
7887
|
+
}
|
|
7888
|
+
if (skipped !== void 0) {
|
|
7889
|
+
log.line(`${tag} no code review: ${skipped}`);
|
|
7890
|
+
return;
|
|
7891
|
+
}
|
|
7892
|
+
}
|
|
6894
7893
|
const agent = judgeAgent(runtime.agents);
|
|
6895
7894
|
if (agent?.adapter.headless === void 0) return await fail(check, `${agent?.descriptor.label ?? "the agent list"} has no headless part, so it cannot run the judge`);
|
|
6896
7895
|
const missing = noAgentProgram(agent.descriptor.label);
|
|
@@ -6899,13 +7898,13 @@ async function runJudge(input) {
|
|
|
6899
7898
|
const expected = (job.container ?? job.microvm)?.judgeProgram;
|
|
6900
7899
|
if (expected === void 0) return await fail(check, missing);
|
|
6901
7900
|
const brief = check.judge.text;
|
|
6902
|
-
if (brief === void 0) return await fail(check, `the brief ${check.judge.brief} is not in the definitions repository`);
|
|
7901
|
+
if (brief === void 0) return await fail(check, check.builtIn === true ? `this CLI holds no ${check.judge.brief}` : `the brief ${check.judge.brief} is not in the definitions repository`);
|
|
6903
7902
|
if (tokens === void 0) return await fail(check, "the build's repository tokens are no longer held, so the branch cannot be fetched");
|
|
6904
7903
|
const credential = config.managed === true && managedClaudeKeyFor(jobDir) !== void 0 ? managedAgentCredential(runtime.agents) : agentCredential(runtime.hostEnv, {}, runtime.agents);
|
|
6905
7904
|
if (credential === void 0) return await fail(check, `the host holds no ${agent.descriptor.credentials.label} credential for the judge`);
|
|
6906
7905
|
const branch = job.branch;
|
|
6907
7906
|
if (branch === void 0) return await fail(check, "the build pushed no branch: the claim names none");
|
|
6908
|
-
const remote =
|
|
7907
|
+
const remote = remoteOf();
|
|
6909
7908
|
try {
|
|
6910
7909
|
await environment.stop();
|
|
6911
7910
|
} catch (err) {
|
|
@@ -6998,6 +7997,16 @@ async function runJudge(input) {
|
|
|
6998
7997
|
const run = outcome === "timeout" ? { kind: "timeout" } : { kind: "exited", status: outcome.status, stdout: outcome.stdout, stderr: outcome.stderr };
|
|
6999
7998
|
return { reply: readJudgeReply(run, minutes, runtime.agents), answer: parseJudgeAnswer(answerText), report };
|
|
7000
7999
|
};
|
|
8000
|
+
const linkTo = (path, line2) => {
|
|
8001
|
+
const href = finder.testHref(repo, head, path, line2 ?? 1);
|
|
8002
|
+
return href !== null && href.length <= CHECK_ITEM_HREF_MAX_LENGTH && /^https:\/\/\S+$/.test(href) ? { href } : {};
|
|
8003
|
+
};
|
|
8004
|
+
let ownTree = false;
|
|
8005
|
+
try {
|
|
8006
|
+
lstatSync(join(branchDir, "tree"));
|
|
8007
|
+
ownTree = true;
|
|
8008
|
+
} catch {
|
|
8009
|
+
}
|
|
7001
8010
|
if (criteria === void 0) {
|
|
7002
8011
|
let ran;
|
|
7003
8012
|
try {
|
|
@@ -7005,20 +8014,15 @@ async function runJudge(input) {
|
|
|
7005
8014
|
} catch (err) {
|
|
7006
8015
|
return await fail(check, `the judge could not be run: ${describeCallFailure(err)}`);
|
|
7007
8016
|
}
|
|
7008
|
-
|
|
8017
|
+
const place = (path, line2) => treeFileText(branchDir, path) === void 0 ? {} : linkTo(path, line2);
|
|
8018
|
+
const items2 = ran.answer?.ok === true ? wholeItems({ answer: ran.answer.answer, commit: head, treeRoot: JUDGE_TREE, place, ownTree, patch: diff, clean: cleanReason }) : void 0;
|
|
8019
|
+
return await finishWhole(check, { ...ran, items: items2, head, branch });
|
|
7009
8020
|
}
|
|
7010
8021
|
const testAt = (path, line2) => {
|
|
7011
8022
|
if (treeFileText(branchDir, path) === void 0) return void 0;
|
|
7012
8023
|
if (!isTest(path)) return "not-a-test";
|
|
7013
|
-
|
|
7014
|
-
return href !== null && href.length <= CHECK_ITEM_HREF_MAX_LENGTH && /^https:\/\/\S+$/.test(href) ? { href } : {};
|
|
8024
|
+
return linkTo(path, line2);
|
|
7015
8025
|
};
|
|
7016
|
-
let ownTree = false;
|
|
7017
|
-
try {
|
|
7018
|
-
lstatSync(join(branchDir, "tree"));
|
|
7019
|
-
ownTree = true;
|
|
7020
|
-
} catch {
|
|
7021
|
-
}
|
|
7022
8026
|
const groups = judgeGroups(plan.toJudge);
|
|
7023
8027
|
const items = [...plan.settled];
|
|
7024
8028
|
const unanswered = [];
|
|
@@ -7074,25 +8078,31 @@ async function runJudge(input) {
|
|
|
7074
8078
|
async function finishWhole(check, at) {
|
|
7075
8079
|
const where = { head: at.head, branch: at.branch };
|
|
7076
8080
|
if (at.answer?.ok === true) {
|
|
7077
|
-
const
|
|
7078
|
-
|
|
7079
|
-
return { id: entry.id, result: entry.result, ...reason2 === void 0 ? {} : { reason: reason2 } };
|
|
7080
|
-
});
|
|
7081
|
-
const failing = itemsSentence(items, { one: "check item", many: "check items" });
|
|
8081
|
+
const answered = at.items ?? [];
|
|
8082
|
+
const failing = itemsSentence(answered, { one: "check item", many: "check items" });
|
|
7082
8083
|
const said2 = at.answer.answer.result ?? (at.reply.kind === "answered" ? at.reply.verdict : void 0);
|
|
7083
8084
|
const result = said2 === "pass" && failing === void 0 ? "pass" : "fail";
|
|
7084
8085
|
const reason = failing ?? (said2 === "fail" ? "the judge failed the change" : said2 === void 0 ? at.reply.kind === "none" ? at.reply.reason : "the judge gave no result" : void 0);
|
|
8086
|
+
const items = said2 === void 0 && failing === void 0 ? [...answered, ...notRunItems(reason ?? "the judge gave no result")] : answered;
|
|
7085
8087
|
const report = renderJudgeReport({ check: check.name, result, reason, items, commit: at.head });
|
|
7086
8088
|
return await recordWhole(check, { ...where, result, reason, items, report });
|
|
7087
8089
|
}
|
|
7088
|
-
if (at.reply.kind === "none")
|
|
7089
|
-
|
|
8090
|
+
if (at.reply.kind === "none") {
|
|
8091
|
+
const limitKey = at.reply.limitKey === true;
|
|
8092
|
+
const items = notRunItems(`${at.reply.reason}${limitKey ? LIMIT_KEY_TAIL : ""}`);
|
|
8093
|
+
return await recordWhole(check, { ...where, result: "fail", reason: at.reply.reason, items, report: at.report, limitKey });
|
|
8094
|
+
}
|
|
8095
|
+
if (at.answer !== void 0) return await recordWhole(check, { ...where, result: "fail", reason: at.answer.reason, items: notRunItems(at.answer.reason), report: at.report });
|
|
7090
8096
|
const failed = at.reply.verdict === "fail";
|
|
7091
8097
|
return await recordWhole(check, { ...where, result: at.reply.verdict, reason: failed ? "the judge failed the change" : void 0, report: at.report });
|
|
7092
8098
|
}
|
|
7093
8099
|
async function recordWhole(check, at) {
|
|
7094
8100
|
const link = at.report === void 0 ? void 0 : await uploadReport(check, at.report, { branch: at.branch, head: at.head });
|
|
7095
|
-
|
|
8101
|
+
const named = at.items ?? [];
|
|
8102
|
+
const notRun = named.some((item) => item.id === JUDGE_NOT_RUN_ITEM_ID);
|
|
8103
|
+
const complete = at.result === "fail" ? named.some((item) => item.result === "fail") : named.some((item) => item.commit !== void 0);
|
|
8104
|
+
const items = check.builtIn === true && !notRun && !complete ? [...named, { id: REVIEWED_COMMIT_ITEM_ID, result: at.result, commit: at.head, ...at.reason === void 0 ? {} : { reason: at.reason } }] : at.items;
|
|
8105
|
+
await record(check.name, at.result, at.reason, { keyTail: at.limitKey === true ? LIMIT_KEY_TAIL : "", link, items: sendable(items) });
|
|
7096
8106
|
}
|
|
7097
8107
|
function sendable(items) {
|
|
7098
8108
|
if (items === void 0) return void 0;
|
|
@@ -7121,11 +8131,11 @@ async function runJudge(input) {
|
|
|
7121
8131
|
schemaVersion: 1,
|
|
7122
8132
|
artifact: {
|
|
7123
8133
|
clientArtifactId,
|
|
7124
|
-
filename: "criteria-judge-report.html",
|
|
8134
|
+
filename: check.judge.subjects === "none" ? "judge-report.html" : "criteria-judge-report.html",
|
|
7125
8135
|
mediaType: "text/html",
|
|
7126
8136
|
bytes: bytes.length,
|
|
7127
8137
|
sha256: createHash("sha256").update(bytes).digest("hex"),
|
|
7128
|
-
caption: REPORT_CAPTION,
|
|
8138
|
+
caption: check.judge.subjects === "none" ? WHOLE_REPORT_CAPTION : REPORT_CAPTION,
|
|
7129
8139
|
criterionId: check.name,
|
|
7130
8140
|
emittedAt: now().toISOString(),
|
|
7131
8141
|
repository: repo,
|
|
@@ -7377,10 +8387,10 @@ function readReasonLine(jobDirPath, config, home = homeFromEnv()) {
|
|
|
7377
8387
|
}
|
|
7378
8388
|
return scrubReason(raw.split(/\r\n|\r|\n/)[0] ?? "", config, home, jobDirPath);
|
|
7379
8389
|
}
|
|
7380
|
-
function scrubReason(line2, config, home = homeFromEnv(), jobDir) {
|
|
8390
|
+
function scrubReason(line2, config, home = homeFromEnv(), jobDir, max = REASON_MAX2) {
|
|
7381
8391
|
installScrubContext(home, releaseScrub(config, home, jobDir));
|
|
7382
8392
|
const oneLine = scrubText(stripUnsendableReasonChars(line2)).replace(/[\r\n]+/g, " ");
|
|
7383
|
-
const trimmed = cutReasonLine(oneLine).trim();
|
|
8393
|
+
const trimmed = cutReasonLine(oneLine, max).trim();
|
|
7384
8394
|
return trimmed.length > 0 ? trimmed : void 0;
|
|
7385
8395
|
}
|
|
7386
8396
|
function scrubTunnelRecord(record, config, jobDir) {
|
|
@@ -7705,6 +8715,7 @@ async function finishJob(job, jobDirPath, outcome, config, deps, ending) {
|
|
|
7705
8715
|
}
|
|
7706
8716
|
const build = job.container === void 0 ? void 0 : { state: job.container, runtime: deps.container ?? createContainerRuntime() };
|
|
7707
8717
|
const vmBuild = job.microvm === void 0 ? void 0 : { state: job.microvm, runtime: deps.container ?? createContainerRuntime() };
|
|
8718
|
+
const sandboxBuild = job.sandbox === void 0 ? void 0 : { state: job.sandbox, runtime: deps.container ?? createContainerRuntime() };
|
|
7708
8719
|
const commandMayRun = job.pid !== void 0 && isGroupAlive(job.pid) || isContainerTracked(job) && job.exitCode === void 0;
|
|
7709
8720
|
if (vmBuild !== void 0) {
|
|
7710
8721
|
const sample = await sampleGuest(vmBuild.runtime, vmBuild.state);
|
|
@@ -7716,6 +8727,9 @@ async function finishJob(job, jobDirPath, outcome, config, deps, ending) {
|
|
|
7716
8727
|
if (vmBuild !== void 0 && isMicroVmTracked(job) && job.exitCode === void 0) {
|
|
7717
8728
|
await endMicroVmCommand(vmBuild.runtime, vmBuild.state, jobDirPath, (line2) => log.error(`${tag} ${line2}`));
|
|
7718
8729
|
}
|
|
8730
|
+
if (sandboxBuild !== void 0 && isSandboxTracked(job) && job.exitCode === void 0) {
|
|
8731
|
+
await endSandboxCommand(sandboxBuild.runtime, sandboxBuild.state, jobDirPath, (line2) => log.error(`${tag} ${line2}`));
|
|
8732
|
+
}
|
|
7719
8733
|
if (build !== void 0 && commandMayRun) {
|
|
7720
8734
|
if (isContainerTracked(job) && build.state.stopped !== true) {
|
|
7721
8735
|
await copyCommandLogTail(build.runtime, build.state, jobDirPath).catch((err) => {
|
|
@@ -7753,14 +8767,14 @@ async function finishJob(job, jobDirPath, outcome, config, deps, ending) {
|
|
|
7753
8767
|
log.error(`${tag} sync skipped: ${VALUES_NOT_HELD}`);
|
|
7754
8768
|
return;
|
|
7755
8769
|
}
|
|
7756
|
-
if (job.container === void 0 && job.microvm === void 0 && job.build?.exec === void 0 && workdirProblem(workdir) !== void 0) {
|
|
8770
|
+
if (job.container === void 0 && job.microvm === void 0 && job.sandbox === void 0 && job.build?.exec === void 0 && workdirProblem(workdir) !== void 0) {
|
|
7757
8771
|
log.line(`${tag} sync skipped: workdir ${workdir} is gone`);
|
|
7758
8772
|
} else if (job.itemKey === void 0) {
|
|
7759
8773
|
log.line(`${tag} sync skipped: the job file holds no item key`);
|
|
7760
8774
|
} else {
|
|
7761
8775
|
log.line(`${tag} sync started`);
|
|
7762
8776
|
const startedMs = now().getTime();
|
|
7763
|
-
const sync = build !== void 0 ? await syncInContainer({ config, runtime: build.runtime, job, jobDir: jobDirPath, log: (line2) => log.line(`${tag} ${line2}`) }) : vmBuild !== void 0 ? await syncInMicroVm({ config, runtime: vmBuild.runtime, job, jobDir: jobDirPath }) : job.build?.exec !== void 0 ? await runSyncViaExec(config, job, jobDirPath, spawnFn) : await runSync(claimCalls(config, job), job.item, job.itemKey, workdir, jobDirPath, spawnFn, job.branch, job.commitIdentity?.author, spoolHomeFor(config, job));
|
|
8777
|
+
const sync = build !== void 0 ? await syncInContainer({ config, runtime: build.runtime, job, jobDir: jobDirPath, log: (line2) => log.line(`${tag} ${line2}`) }) : vmBuild !== void 0 ? await syncInMicroVm({ config, runtime: vmBuild.runtime, job, jobDir: jobDirPath }) : sandboxBuild !== void 0 ? await syncInSandbox({ config, runtime: sandboxBuild.runtime, job, jobDir: jobDirPath, log: (line2) => log.line(`${tag} ${line2}`) }) : job.build?.exec !== void 0 ? await runSyncViaExec(config, job, jobDirPath, spawnFn) : await runSync(claimCalls(config, job), job.item, job.itemKey, workdir, jobDirPath, spawnFn, job.branch, job.commitIdentity?.author, spoolHomeFor(config, job));
|
|
7764
8778
|
const took = formatDuration(now().getTime() - startedMs);
|
|
7765
8779
|
if (sync.ok) log.line(`${tag} sync ok (${took})`);
|
|
7766
8780
|
else log.error(`${tag} sync failed: ${sync.reason ?? "no reason given"} \xB7 continuing`);
|
|
@@ -7829,7 +8843,7 @@ async function finishJob(job, jobDirPath, outcome, config, deps, ending) {
|
|
|
7829
8843
|
log.line(`${tag} proofs started`);
|
|
7830
8844
|
const startedMs = now().getTime();
|
|
7831
8845
|
try {
|
|
7832
|
-
const recorded = build !== void 0 ? await recordProofsInContainer({ config, runtime: build.runtime, job, jobDir: jobDirPath, log: (line2) => log.line(`${tag} ${line2}`) }) : vmBuild !== void 0 ? await recordProofsInMicroVm({ config, runtime: vmBuild.runtime, job, jobDir: jobDirPath }) : job.build?.exec !== void 0 ? await runRecordProofsViaExec(config, job, jobDirPath, spawnFn) : await runRecordProofs(config, job, jobDirPath, spawnFn);
|
|
8846
|
+
const recorded = build !== void 0 ? await recordProofsInContainer({ config, runtime: build.runtime, job, jobDir: jobDirPath, log: (line2) => log.line(`${tag} ${line2}`) }) : vmBuild !== void 0 ? await recordProofsInMicroVm({ config, runtime: vmBuild.runtime, job, jobDir: jobDirPath }) : sandboxBuild !== void 0 ? await recordProofsInSandbox({ config, runtime: sandboxBuild.runtime, job, jobDir: jobDirPath, log: (line2) => log.line(`${tag} ${line2}`) }) : job.build?.exec !== void 0 ? await runRecordProofsViaExec(config, job, jobDirPath, spawnFn) : await runRecordProofs(config, job, jobDirPath, spawnFn);
|
|
7833
8847
|
const took = formatDuration(now().getTime() - startedMs);
|
|
7834
8848
|
if (recorded.ok) log.line(`${tag} proofs ok (${took}) \xB7 see ${PROOFS_LOG}`);
|
|
7835
8849
|
else log.error(`${tag} proofs not all current (${took}): ${recorded.reason ?? "no reason given"} \xB7 see ${PROOFS_LOG} \xB7 continuing`);
|
|
@@ -7838,7 +8852,11 @@ async function finishJob(job, jobDirPath, outcome, config, deps, ending) {
|
|
|
7838
8852
|
}
|
|
7839
8853
|
}
|
|
7840
8854
|
if (valuesNotHeld && outcome === "ok" && !job.cleanupRan) log.error(`${tag} the host's judge and checks skipped: ${VALUES_NOT_HELD}`);
|
|
7841
|
-
if (outcome === "ok" && !job.cleanupRan && job.
|
|
8855
|
+
if (outcome === "ok" && !job.cleanupRan && job.sandbox !== void 0 && job.judgeRan !== true) {
|
|
8856
|
+
job.judgeNotRun = "the host's judge and checks do not run for a build in a sandbox";
|
|
8857
|
+
log.line(`${tag} the host's judge and checks are not run for a build in a sandbox`);
|
|
8858
|
+
}
|
|
8859
|
+
if (outcome === "ok" && !job.cleanupRan && job.judgeRan !== true && !valuesNotHeld && job.sandbox === void 0) {
|
|
7842
8860
|
setStage(job, jobDirPath, "judge");
|
|
7843
8861
|
job.judgeRan = true;
|
|
7844
8862
|
writeJobFile(jobFilePath, job);
|
|
@@ -7853,7 +8871,7 @@ async function finishJob(job, jobDirPath, outcome, config, deps, ending) {
|
|
|
7853
8871
|
log.error(`${tag} the host's judge stopped: ${describeCallFailure(err)} \xB7 continuing`);
|
|
7854
8872
|
}
|
|
7855
8873
|
}
|
|
7856
|
-
if (outcome === "ok" && !job.cleanupRan && job.checksRan !== true && !valuesNotHeld) {
|
|
8874
|
+
if (outcome === "ok" && !job.cleanupRan && job.checksRan !== true && !valuesNotHeld && job.sandbox === void 0) {
|
|
7857
8875
|
setStage(job, jobDirPath, "checks");
|
|
7858
8876
|
job.checksRan = true;
|
|
7859
8877
|
writeJobFile(jobFilePath, job);
|
|
@@ -7921,6 +8939,17 @@ async function finishJob(job, jobDirPath, outcome, config, deps, ending) {
|
|
|
7921
8939
|
}
|
|
7922
8940
|
if (cleanedUp && !buildVmStopLogged) log.line(`${tag} build microVM stopped`);
|
|
7923
8941
|
if (cleanedUp) log.line(`${tag} cleanup ok (${formatDuration(now().getTime() - cleanupStartedMs)})`);
|
|
8942
|
+
} else if (sandboxBuild !== void 0) {
|
|
8943
|
+
let cleanedUp = true;
|
|
8944
|
+
tunnelRecord = sandboxBuild.runtime.tunnels.get(sandboxBuild.state.buildId)?.record();
|
|
8945
|
+
try {
|
|
8946
|
+
await cleanupSandbox(sandboxBuild.runtime, sandboxBuild.state);
|
|
8947
|
+
log.line(`${tag} ended sandbox ${sandboxBuild.state.sandboxId}`);
|
|
8948
|
+
} catch (err) {
|
|
8949
|
+
cleanedUp = false;
|
|
8950
|
+
log.error(`${tag} cleanup failed: ${describeCallFailure(err)} \xB7 continuing`);
|
|
8951
|
+
}
|
|
8952
|
+
if (cleanedUp) log.line(`${tag} cleanup ok (${formatDuration(now().getTime() - cleanupStartedMs)})`);
|
|
7924
8953
|
} else if (build !== void 0 || !hostMade && isBuiltinContainer(config.hooks.cleanup)) {
|
|
7925
8954
|
let cleanedUp = true;
|
|
7926
8955
|
if (build !== void 0) {
|
|
@@ -7934,7 +8963,7 @@ async function finishJob(job, jobDirPath, outcome, config, deps, ending) {
|
|
|
7934
8963
|
}
|
|
7935
8964
|
if (cleanedUp) log.line(`${tag} cleanup ok (${formatDuration(now().getTime() - cleanupStartedMs)})`);
|
|
7936
8965
|
} else {
|
|
7937
|
-
if (!isBuiltinContainer(config.hooks.cleanup) && !isBuiltinVm(config.hooks.cleanup)) {
|
|
8966
|
+
if (!isBuiltinContainer(config.hooks.cleanup) && !isBuiltinVm(config.hooks.cleanup) && !isBuiltinSandbox(config.hooks.cleanup)) {
|
|
7938
8967
|
const cleanupEnv = {
|
|
7939
8968
|
...jobEnv(claimCalls(config, job), job.item, job.itemKey, jobDirPath, process.env, job.branch, job.commitIdentity?.author, spoolHomeFor(config, job)),
|
|
7940
8969
|
...job.build === void 0 ? {} : { OUTERLAYER_BUILD_DIR: job.build.buildDir },
|
|
@@ -8021,7 +9050,7 @@ async function finishJob(job, jobDirPath, outcome, config, deps, ending) {
|
|
|
8021
9050
|
log.error(`${tag} report exited ${report.code} (${reportTook}) \xB7 continuing`);
|
|
8022
9051
|
}
|
|
8023
9052
|
}
|
|
8024
|
-
const isolated = job
|
|
9053
|
+
const isolated = isIsolatedJob(job);
|
|
8025
9054
|
const held3 = deps.container?.credentials.get(jobDirPath);
|
|
8026
9055
|
if (held3 !== void 0) {
|
|
8027
9056
|
await held3.revokeAll();
|
|
@@ -8041,7 +9070,7 @@ async function finishJob(job, jobDirPath, outcome, config, deps, ending) {
|
|
|
8041
9070
|
job.reason = scrubReason(job.commandEndReason, config, void 0, jobDirPath);
|
|
8042
9071
|
}
|
|
8043
9072
|
const cliVersion = deps.cliVersion ?? resolveVersion();
|
|
8044
|
-
const base = job.environment ?? (job.microvm !== void 0 ? { isolation: "vm", cliVersion } : job
|
|
9073
|
+
const base = job.environment ?? (job.microvm !== void 0 ? { isolation: "vm", cliVersion } : !isIsolatedJob(job) ? sharedUserEnvironment(cliVersion) : { isolation: "container", cliVersion });
|
|
8045
9074
|
if (isolated || job.build !== void 0) {
|
|
8046
9075
|
tunnelRecord ??= readTunnelRecord(join(jobDirPath, "tunnel.json"));
|
|
8047
9076
|
job.environment = withTunnelRecord(base, scrubTunnelRecord(tunnelRecord, config, jobDirPath), !isolated);
|
|
@@ -8174,8 +9203,14 @@ function isContainerTracked(job) {
|
|
|
8174
9203
|
function isMicroVmTracked(job) {
|
|
8175
9204
|
return job.microvm?.tracking === "microvm";
|
|
8176
9205
|
}
|
|
9206
|
+
function isSandboxTracked(job) {
|
|
9207
|
+
return job.sandbox?.tracking === "sandbox";
|
|
9208
|
+
}
|
|
8177
9209
|
function isTracked(job) {
|
|
8178
|
-
return isContainerTracked(job) || isMicroVmTracked(job);
|
|
9210
|
+
return isContainerTracked(job) || isMicroVmTracked(job) || isSandboxTracked(job);
|
|
9211
|
+
}
|
|
9212
|
+
function isIsolatedJob(job) {
|
|
9213
|
+
return job.container !== void 0 || job.microvm !== void 0 || job.sandbox !== void 0;
|
|
8179
9214
|
}
|
|
8180
9215
|
function trackingOf(job) {
|
|
8181
9216
|
return job.container?.tracking ?? job.microvm?.tracking;
|
|
@@ -9556,227 +10591,6 @@ async function sweepImageBuilders(configPath, ports, onError) {
|
|
|
9556
10591
|
}
|
|
9557
10592
|
return swept;
|
|
9558
10593
|
}
|
|
9559
|
-
var noop = () => void 0;
|
|
9560
|
-
var FRAME_HEADER_BYTES = 9;
|
|
9561
|
-
var GOAWAY_FRAME = 7;
|
|
9562
|
-
function describeGoawayCode(code) {
|
|
9563
|
-
const names = [
|
|
9564
|
-
"NO_ERROR",
|
|
9565
|
-
"PROTOCOL_ERROR",
|
|
9566
|
-
"INTERNAL_ERROR",
|
|
9567
|
-
"FLOW_CONTROL_ERROR",
|
|
9568
|
-
"SETTINGS_TIMEOUT",
|
|
9569
|
-
"STREAM_CLOSED",
|
|
9570
|
-
"FRAME_SIZE_ERROR",
|
|
9571
|
-
"REFUSED_STREAM",
|
|
9572
|
-
"CANCEL",
|
|
9573
|
-
"COMPRESSION_ERROR",
|
|
9574
|
-
"CONNECT_ERROR",
|
|
9575
|
-
"ENHANCE_YOUR_CALM",
|
|
9576
|
-
"INADEQUATE_SECURITY",
|
|
9577
|
-
"HTTP_1_1_REQUIRED"
|
|
9578
|
-
];
|
|
9579
|
-
const name = names[code];
|
|
9580
|
-
return name === void 0 ? `error code ${code}` : `${name} (${code})`;
|
|
9581
|
-
}
|
|
9582
|
-
function goawayNote(label, code) {
|
|
9583
|
-
return code === void 0 ? "" : ` \xB7 ${label} ${describeGoawayCode(code)}`;
|
|
9584
|
-
}
|
|
9585
|
-
function watchSentGoaway(onError) {
|
|
9586
|
-
let head = Buffer.alloc(0);
|
|
9587
|
-
let want = FRAME_HEADER_BYTES;
|
|
9588
|
-
let skip = 0;
|
|
9589
|
-
return (chunk) => {
|
|
9590
|
-
let at = 0;
|
|
9591
|
-
while (at < chunk.length) {
|
|
9592
|
-
if (skip > 0) {
|
|
9593
|
-
const n = Math.min(skip, chunk.length - at);
|
|
9594
|
-
skip -= n;
|
|
9595
|
-
at += n;
|
|
9596
|
-
continue;
|
|
9597
|
-
}
|
|
9598
|
-
const take = Math.min(want - head.length, chunk.length - at);
|
|
9599
|
-
head = Buffer.concat([head, chunk.subarray(at, at + take)]);
|
|
9600
|
-
at += take;
|
|
9601
|
-
if (head.length < want) return;
|
|
9602
|
-
const length = head.readUIntBE(0, 3);
|
|
9603
|
-
if (want === FRAME_HEADER_BYTES && head[3] === GOAWAY_FRAME && length >= 8) {
|
|
9604
|
-
want = FRAME_HEADER_BYTES + 8;
|
|
9605
|
-
continue;
|
|
9606
|
-
}
|
|
9607
|
-
if (want > FRAME_HEADER_BYTES) {
|
|
9608
|
-
const code = head.readUInt32BE(FRAME_HEADER_BYTES + 4);
|
|
9609
|
-
if (code !== http2.constants.NGHTTP2_NO_ERROR) onError(code);
|
|
9610
|
-
}
|
|
9611
|
-
skip = length - (want - FRAME_HEADER_BYTES);
|
|
9612
|
-
head = Buffer.alloc(0);
|
|
9613
|
-
want = FRAME_HEADER_BYTES;
|
|
9614
|
-
}
|
|
9615
|
-
};
|
|
9616
|
-
}
|
|
9617
|
-
function writeStringsAsBuffers(stream) {
|
|
9618
|
-
const own = stream._writev;
|
|
9619
|
-
if (typeof own !== "function") return;
|
|
9620
|
-
stream._writev = function(chunks, callback) {
|
|
9621
|
-
const buffers = chunks.map(({ chunk, encoding }) => ({
|
|
9622
|
-
chunk: typeof chunk === "string" ? Buffer.from(chunk, encoding) : chunk,
|
|
9623
|
-
encoding: "buffer"
|
|
9624
|
-
}));
|
|
9625
|
-
buffers.allBuffers = true;
|
|
9626
|
-
own.call(this, buffers, callback);
|
|
9627
|
-
};
|
|
9628
|
-
}
|
|
9629
|
-
function serveSession(transport, services, opts = {}) {
|
|
9630
|
-
const maxStreams = opts.maxStreams ?? MAX_OPEN_STREAMS;
|
|
9631
|
-
let open = 0;
|
|
9632
|
-
let served = 0;
|
|
9633
|
-
let malformed = false;
|
|
9634
|
-
let goawayCode;
|
|
9635
|
-
transport.on("error", noop);
|
|
9636
|
-
const watch = watchSentGoaway((code) => {
|
|
9637
|
-
malformed = true;
|
|
9638
|
-
goawayCode ??= code;
|
|
9639
|
-
setImmediate(() => session.destroy());
|
|
9640
|
-
});
|
|
9641
|
-
const outbound = new Transform({
|
|
9642
|
-
transform(chunk, _encoding, done) {
|
|
9643
|
-
watch(chunk);
|
|
9644
|
-
done(null, chunk);
|
|
9645
|
-
}
|
|
9646
|
-
});
|
|
9647
|
-
outbound.on("error", noop);
|
|
9648
|
-
outbound.pipe(transport);
|
|
9649
|
-
const wire = Duplex.from({ readable: transport, writable: outbound });
|
|
9650
|
-
wire.on("error", noop);
|
|
9651
|
-
const session = http2.performServerHandshake(wire, {
|
|
9652
|
-
settings: { initialWindowSize: STREAM_WINDOW, enablePush: false },
|
|
9653
|
-
streamResetBurst: STREAM_RESET_BURST,
|
|
9654
|
-
streamResetRate: STREAM_RESET_RATE
|
|
9655
|
-
});
|
|
9656
|
-
try {
|
|
9657
|
-
session.setLocalWindowSize(SESSION_WINDOW);
|
|
9658
|
-
} catch {
|
|
9659
|
-
}
|
|
9660
|
-
const ended = new Promise((resolve2) => {
|
|
9661
|
-
session.on("error", (err) => {
|
|
9662
|
-
if (typeof err.code === "string" && err.code.startsWith("ERR_HTTP2_")) malformed = true;
|
|
9663
|
-
});
|
|
9664
|
-
session.on("goaway", (code) => {
|
|
9665
|
-
if (code !== http2.constants.NGHTTP2_NO_ERROR) goawayCode ??= code;
|
|
9666
|
-
});
|
|
9667
|
-
session.on("close", () => resolve2({ malformed, served, goawayCode }));
|
|
9668
|
-
});
|
|
9669
|
-
session.on("stream", (stream, headers) => {
|
|
9670
|
-
stream.on("error", noop);
|
|
9671
|
-
const target2 = headers[":method"] === "POST" ? targetOfPath(headers[":path"], opts.builtIns) : void 0;
|
|
9672
|
-
if (target2 === void 0 || open >= maxStreams) {
|
|
9673
|
-
stream.close(http2.constants.NGHTTP2_REFUSED_STREAM);
|
|
9674
|
-
return;
|
|
9675
|
-
}
|
|
9676
|
-
open++;
|
|
9677
|
-
stream.once("close", () => {
|
|
9678
|
-
open--;
|
|
9679
|
-
});
|
|
9680
|
-
writeStringsAsBuffers(stream);
|
|
9681
|
-
if (!services.accept(target2, stream)) {
|
|
9682
|
-
stream.close(http2.constants.NGHTTP2_REFUSED_STREAM);
|
|
9683
|
-
return;
|
|
9684
|
-
}
|
|
9685
|
-
served++;
|
|
9686
|
-
if (!stream.headersSent && !stream.destroyed) stream.respond({ ":status": 200 });
|
|
9687
|
-
});
|
|
9688
|
-
return {
|
|
9689
|
-
ended,
|
|
9690
|
-
// A session the peer is closing gracefully waits for its open streams, which a stopped container never ends: destroy it whatever its state.
|
|
9691
|
-
close: () => {
|
|
9692
|
-
if (!session.destroyed) session.destroy();
|
|
9693
|
-
}
|
|
9694
|
-
};
|
|
9695
|
-
}
|
|
9696
|
-
var FIRST_BACKOFF_MS = 200;
|
|
9697
|
-
var LONGEST_BACKOFF_MS = 5e3;
|
|
9698
|
-
var JOINED_AFTER_MS = 2e3;
|
|
9699
|
-
var EXIT_WAIT_MS = 5e3;
|
|
9700
|
-
var SOCKET_NOT_READY = /\b(ENOENT|ECONNREFUSED)\b/;
|
|
9701
|
-
function exitedWithin(stream, ms) {
|
|
9702
|
-
let timer;
|
|
9703
|
-
const late = new Promise((resolve2) => {
|
|
9704
|
-
timer = setTimeout(() => resolve2(void 0), ms);
|
|
9705
|
-
timer.unref();
|
|
9706
|
-
});
|
|
9707
|
-
return Promise.race([stream.exited, late]).finally(() => clearTimeout(timer));
|
|
9708
|
-
}
|
|
9709
|
-
function superviseRelay(input) {
|
|
9710
|
-
const sleep = input.sleep ?? ((ms) => new Promise((resolve2) => setTimeout(resolve2, ms)));
|
|
9711
|
-
const exitWaitMs = input.exitWaitMs ?? EXIT_WAIT_MS;
|
|
9712
|
-
const now = input.now ?? Date.now;
|
|
9713
|
-
const startedAt = now();
|
|
9714
|
-
let closed = false;
|
|
9715
|
-
let fatal;
|
|
9716
|
-
let running;
|
|
9717
|
-
let wake;
|
|
9718
|
-
const loop = (async () => {
|
|
9719
|
-
let malformedInARow = 0;
|
|
9720
|
-
let backoff = FIRST_BACKOFF_MS;
|
|
9721
|
-
let failing = false;
|
|
9722
|
-
while (!closed && fatal === void 0) {
|
|
9723
|
-
const startedMs = Date.now();
|
|
9724
|
-
const stream = input.execStream({
|
|
9725
|
-
container: input.container,
|
|
9726
|
-
user: RELAY_USER,
|
|
9727
|
-
env: { literals: {}, passed: {} },
|
|
9728
|
-
argv: ["outerlayer", "broker-relay", "join"],
|
|
9729
|
-
interactive: true
|
|
9730
|
-
});
|
|
9731
|
-
stream.stdin.on("error", noop);
|
|
9732
|
-
stream.stdout.on("error", noop);
|
|
9733
|
-
const session = serveSession(Duplex.from({ readable: stream.stdout, writable: stream.stdin }), input.services, { builtIns: input.builtIns });
|
|
9734
|
-
running = { stream, session };
|
|
9735
|
-
void stream.exited.then(() => session.close());
|
|
9736
|
-
const end = await session.ended;
|
|
9737
|
-
stream.kill();
|
|
9738
|
-
const status = await exitedWithin(stream, exitWaitMs);
|
|
9739
|
-
running = void 0;
|
|
9740
|
-
if (status === void 0) input.log?.(`the relay's exec into ${input.container} did not end when killed \xB7 going on without it`);
|
|
9741
|
-
const joined = end.served > 0 || Date.now() - startedMs >= JOINED_AFTER_MS;
|
|
9742
|
-
if (joined) {
|
|
9743
|
-
backoff = FIRST_BACKOFF_MS;
|
|
9744
|
-
failing = false;
|
|
9745
|
-
if (!closed) input.log?.(`the session with ${input.container} ended \xB7 joining again${goawayNote("GOAWAY", end.goawayCode)}`);
|
|
9746
|
-
}
|
|
9747
|
-
if (!end.malformed && end.served > 0) malformedInARow = 0;
|
|
9748
|
-
if (end.malformed) {
|
|
9749
|
-
malformedInARow++;
|
|
9750
|
-
if (malformedInARow >= MAX_MALFORMED_SESSIONS) {
|
|
9751
|
-
fatal = MALFORMED_REASON;
|
|
9752
|
-
input.log?.(`the session with ${input.container} broke HTTP/2 framing ${malformedInARow} times in a row${goawayNote("last GOAWAY", end.goawayCode)} \xB7 ending the build`);
|
|
9753
|
-
input.onFatal?.(fatal);
|
|
9754
|
-
return;
|
|
9755
|
-
}
|
|
9756
|
-
} else if (!joined && !failing) {
|
|
9757
|
-
const reason = stream.stderrTail?.().trim() ?? "";
|
|
9758
|
-
const starting = SOCKET_NOT_READY.test(reason) && now() - startedAt < JOIN_WAIT_MS;
|
|
9759
|
-
if (!starting) {
|
|
9760
|
-
failing = true;
|
|
9761
|
-
input.log?.(`could not join the relay in ${input.container}${status === 0 || status === void 0 ? "" : ` (exec exited ${status})`}${reason === "" ? "" : `: ${reason}`} \xB7 trying again`);
|
|
9762
|
-
}
|
|
9763
|
-
}
|
|
9764
|
-
if (closed) return;
|
|
9765
|
-
await Promise.race([sleep(backoff), new Promise((resolve2) => wake = resolve2)]);
|
|
9766
|
-
backoff = Math.min(backoff * 2, LONGEST_BACKOFF_MS);
|
|
9767
|
-
}
|
|
9768
|
-
})();
|
|
9769
|
-
return {
|
|
9770
|
-
fatal: () => fatal,
|
|
9771
|
-
close: async () => {
|
|
9772
|
-
closed = true;
|
|
9773
|
-
wake?.();
|
|
9774
|
-
running?.session.close();
|
|
9775
|
-
running?.stream.kill();
|
|
9776
|
-
await loop;
|
|
9777
|
-
}
|
|
9778
|
-
};
|
|
9779
|
-
}
|
|
9780
10594
|
function gitEnv(extra) {
|
|
9781
10595
|
const env = {};
|
|
9782
10596
|
for (const [name, value] of Object.entries(process.env)) if (!name.startsWith("GIT_")) env[name] = value;
|
|
@@ -10365,8 +11179,8 @@ async function engineNetworkHelper(host, runnerDir2, ensure = ensureNetworkHelpe
|
|
|
10365
11179
|
|
|
10366
11180
|
// src/runner/container/hooks.ts
|
|
10367
11181
|
var MIN_ENGINE_MAJOR = 26;
|
|
10368
|
-
var
|
|
10369
|
-
var
|
|
11182
|
+
var RELAY_ATTEMPTS2 = 20;
|
|
11183
|
+
var RELAY_WAIT_MS2 = 500;
|
|
10370
11184
|
var BUSY_IMAGE_WAIT_MS = 5e3;
|
|
10371
11185
|
var VOLUME_REMOVE_ATTEMPTS = 4;
|
|
10372
11186
|
function withTunnelLog(opts, log) {
|
|
@@ -10416,6 +11230,7 @@ function createContainerRuntime(opts = {}) {
|
|
|
10416
11230
|
upstreams: opts.upstreams,
|
|
10417
11231
|
agents: opts.agents,
|
|
10418
11232
|
vm,
|
|
11233
|
+
sandbox: createSandboxPorts(opts.sandbox, opts.hostEnv ?? process.env),
|
|
10419
11234
|
cliBuild: () => cli ?? currentCliBuild(),
|
|
10420
11235
|
networkHelper: opts.networkHelper ?? ((dir) => engineNetworkHelper(host, dir)),
|
|
10421
11236
|
ipv6: opts.ipv6 ?? kernelHasIpv6()
|
|
@@ -10481,7 +11296,7 @@ function gitRemoteFor(runtime, input) {
|
|
|
10481
11296
|
...input.readOnly === true ? { readOnly: true } : {}
|
|
10482
11297
|
});
|
|
10483
11298
|
}
|
|
10484
|
-
var
|
|
11299
|
+
var NO_ENV2 = { literals: {}, passed: {} };
|
|
10485
11300
|
function transportOf(state) {
|
|
10486
11301
|
const recorded = state.transport;
|
|
10487
11302
|
if (recorded === void 0 || recorded === "sockets") return "sockets";
|
|
@@ -10514,17 +11329,17 @@ function rejoinBuild(runtime, state, log) {
|
|
|
10514
11329
|
if (services?.streams === void 0 || runtime.relays.has(state.buildId) || transportOf(state) !== "exec") return;
|
|
10515
11330
|
joinBuild(runtime, state, { streams: services.streams }, log);
|
|
10516
11331
|
}
|
|
10517
|
-
var
|
|
10518
|
-
async function
|
|
10519
|
-
for (let attempt = 0; attempt <
|
|
11332
|
+
var RELAY_PROBE2 = `const s=require("net").connect(${RELAY_PORT},"127.0.0.1");s.on("connect",()=>process.exit(0));s.on("error",()=>process.exit(1));setTimeout(()=>process.exit(1),2000)`;
|
|
11333
|
+
async function waitForRelay2(runtime, state) {
|
|
11334
|
+
for (let attempt = 0; attempt < RELAY_ATTEMPTS2; attempt++) {
|
|
10520
11335
|
const probe = await runtime.host.exec({
|
|
10521
11336
|
container: state.container,
|
|
10522
11337
|
user: relayUserOf(state),
|
|
10523
|
-
env:
|
|
10524
|
-
argv: ["/opt/outerlayer/bin/node", "-e",
|
|
11338
|
+
env: NO_ENV2,
|
|
11339
|
+
argv: ["/opt/outerlayer/bin/node", "-e", RELAY_PROBE2]
|
|
10525
11340
|
});
|
|
10526
11341
|
if (probe.status === 0) return true;
|
|
10527
|
-
await runtime.sleep(
|
|
11342
|
+
await runtime.sleep(RELAY_WAIT_MS2);
|
|
10528
11343
|
}
|
|
10529
11344
|
return false;
|
|
10530
11345
|
}
|
|
@@ -10568,7 +11383,9 @@ async function obtainImage(input) {
|
|
|
10568
11383
|
if (err instanceof RecipeError) {
|
|
10569
11384
|
log.error(`${tag} image build for ${repository} failed: ${err.code}: ${err.message}`);
|
|
10570
11385
|
const says = err.code === "image_build_out_of_memory" || err.code === "image_build_out_of_disk" || err.code === "image_builder_unavailable" || err.code === "image_builder_failed";
|
|
10571
|
-
return { ok: false, reason:
|
|
11386
|
+
if (says) return { ok: false, reason: err.message };
|
|
11387
|
+
const line2 = err.code === "build_failed" ? failedStepLineOf(err.logPath) : void 0;
|
|
11388
|
+
return { ok: false, reason: line2 === void 0 ? err.code : `${err.code}: ${line2}` };
|
|
10572
11389
|
}
|
|
10573
11390
|
return { ok: false, reason: `the image build failed: ${describeCallFailure(err)}` };
|
|
10574
11391
|
}
|
|
@@ -10813,7 +11630,7 @@ async function provisionContainerOnce(input, allowRestore, itemDiskFailed) {
|
|
|
10813
11630
|
if (started.status !== 0) return dockerFailed("starting the build's container", started);
|
|
10814
11631
|
joinBuild(runtime, state, services, (line2) => log.line(`${tag} ${line2}`));
|
|
10815
11632
|
if (input.aborted()) return bail("", true);
|
|
10816
|
-
if (!await
|
|
11633
|
+
if (!await waitForRelay2(runtime, state)) return bail("the relay in the build's container did not start");
|
|
10817
11634
|
const ghDelivered = await deliverJobFiles(runtime, state, ["gh"], secrets);
|
|
10818
11635
|
if (!ghDelivered.ok) return bail(ghDelivered.reason);
|
|
10819
11636
|
keepGhConfigCurrent(tokens, buildDir2, (err) => log.error(`${tag} the read token could not be written for gh: ${describeCallFailure(err)}`), {
|
|
@@ -10823,14 +11640,14 @@ async function provisionContainerOnce(input, allowRestore, itemDiskFailed) {
|
|
|
10823
11640
|
delivered: readToken,
|
|
10824
11641
|
onFailure: (reason) => log.error(`${tag} ${reason}`)
|
|
10825
11642
|
});
|
|
10826
|
-
const agentUidProbe = await host.exec({ container: name, user: ADDED_USER, env:
|
|
11643
|
+
const agentUidProbe = await host.exec({ container: name, user: ADDED_USER, env: NO_ENV2, argv: ["id", "-u", agentUser] });
|
|
10827
11644
|
const agentUid = agentUidOf(agentUidProbe);
|
|
10828
11645
|
const changed = userIdChangedReason(plan.restore?.record.agentUid, agentUid);
|
|
10829
11646
|
if (changed !== void 0) return giveUpState(changed);
|
|
10830
|
-
const tools = await host.exec({ container: name, user: ADDED_USER, env:
|
|
11647
|
+
const tools = await host.exec({ container: name, user: ADDED_USER, env: NO_ENV2, argv: ["cat", "/opt/outerlayer/tools.json"] });
|
|
10831
11648
|
const agentVersion = agentVersionOf(tools.status === 0 ? tools.stdout : "", runtime.agents, input.job);
|
|
10832
11649
|
environment.agentVersion = agentVersion;
|
|
10833
|
-
const recorded = await judgeProgramRecord((argv) => host.exec({ container: name, user: ADDED_USER, env:
|
|
11650
|
+
const recorded = await judgeProgramRecord((argv) => host.exec({ container: name, user: ADDED_USER, env: NO_ENV2, argv }), runtime.agents);
|
|
10834
11651
|
if (recorded !== void 0) state.judgeProgram = recorded;
|
|
10835
11652
|
input.save(state, environment);
|
|
10836
11653
|
const exec = async (argv, workdir, opts) => {
|
|
@@ -11006,7 +11823,7 @@ async function signalInContainer(runtime, state, pidfile, signal) {
|
|
|
11006
11823
|
const { status } = await runtime.host.exec({
|
|
11007
11824
|
container: state.container,
|
|
11008
11825
|
user: state.agentUser ?? ADDED_USER,
|
|
11009
|
-
env:
|
|
11826
|
+
env: NO_ENV2,
|
|
11010
11827
|
argv: ["/bin/sh", "-c", senderSignalScript(pidfile, signal)]
|
|
11011
11828
|
});
|
|
11012
11829
|
return status === 0;
|
|
@@ -11112,7 +11929,7 @@ async function runCliInContainer(input, argv, logName) {
|
|
|
11112
11929
|
if (network !== void 0) return { ok: false, reason: network };
|
|
11113
11930
|
await runtime.host.start(state.container);
|
|
11114
11931
|
state.stopped = false;
|
|
11115
|
-
if (!await
|
|
11932
|
+
if (!await waitForRelay2(runtime, state)) return { ok: false, reason: "the relay did not start again" };
|
|
11116
11933
|
rejoinBuild(runtime, state, input.log);
|
|
11117
11934
|
const delivered = await redeliver(runtime, state, input.jobDir);
|
|
11118
11935
|
if (!delivered.ok) return { ok: false, reason: delivered.reason };
|
|
@@ -11155,7 +11972,7 @@ async function copyTranscriptsFromContainer(runtime, state, job) {
|
|
|
11155
11972
|
} catch (err) {
|
|
11156
11973
|
return { ok: false, reason: describeCallFailure(err) };
|
|
11157
11974
|
}
|
|
11158
|
-
return copyTranscripts((argv) => runtime.host.exec({ container: state.container, user: state.agentUser ?? ADDED_USER, env:
|
|
11975
|
+
return copyTranscripts((argv) => runtime.host.exec({ container: state.container, user: state.agentUser ?? ADDED_USER, env: NO_ENV2, argv }), void 0, runtime.agents, job);
|
|
11159
11976
|
}
|
|
11160
11977
|
async function ensureContainerRunning(runtime, state) {
|
|
11161
11978
|
try {
|
|
@@ -11170,7 +11987,7 @@ async function ensureContainerRunning(runtime, state) {
|
|
|
11170
11987
|
}
|
|
11171
11988
|
}
|
|
11172
11989
|
function sessionGuestOfContainer(runtime, state) {
|
|
11173
|
-
const input = (argv) => ({ container: state.container, user: state.agentUser ?? ADDED_USER, env:
|
|
11990
|
+
const input = (argv) => ({ container: state.container, user: state.agentUser ?? ADDED_USER, env: NO_ENV2, argv });
|
|
11174
11991
|
return {
|
|
11175
11992
|
run: (argv) => runtime.host.exec(input(argv)),
|
|
11176
11993
|
stream: (argv, io) => new Promise((resolve2, reject) => {
|
|
@@ -11207,7 +12024,7 @@ async function copyHookErrors2(runtime, state, jobDir) {
|
|
|
11207
12024
|
const started = await runtime.host.start(state.container);
|
|
11208
12025
|
if (started.status !== 0) return;
|
|
11209
12026
|
}
|
|
11210
|
-
const log = await runtime.host.exec({ container: state.container, user: state.agentUser ?? ADDED_USER, env:
|
|
12027
|
+
const log = await runtime.host.exec({ container: state.container, user: state.agentUser ?? ADDED_USER, env: NO_ENV2, argv: ["cat", HOOK_ERRORS_IN_CONTAINER] });
|
|
11211
12028
|
if (log.status === 0 && log.stdout !== "") writeFileSync(join(jobDir, "hook-errors.log"), log.stdout);
|
|
11212
12029
|
} catch {
|
|
11213
12030
|
}
|
|
@@ -11258,7 +12075,7 @@ function containerJudgeEnvironment(input) {
|
|
|
11258
12075
|
const read = await runtime.host.exec({
|
|
11259
12076
|
container: state.container,
|
|
11260
12077
|
user,
|
|
11261
|
-
env:
|
|
12078
|
+
env: NO_ENV2,
|
|
11262
12079
|
argv: ["/bin/sh", "-c", `[ -f ${file} ] && [ ! -L ${file} ] && head -c ${maxBytes + 1} ${file}`]
|
|
11263
12080
|
}, { timeoutMs: REPORT_READ_TIMEOUT_MS });
|
|
11264
12081
|
if (read.status > 1) throw new Error(`reading the judge's ${name} exited ${read.status}: ${firstLine(read.stderr)}`);
|
|
@@ -11273,13 +12090,13 @@ function containerJudgeEnvironment(input) {
|
|
|
11273
12090
|
const started = await runtime.host.start(state.container);
|
|
11274
12091
|
if (started.status !== 0) throw new Error(`the build's container could not be started again (exit ${started.status})`);
|
|
11275
12092
|
state.stopped = false;
|
|
11276
|
-
if (!await
|
|
12093
|
+
if (!await waitForRelay2(runtime, state)) throw new Error("the relay in the build's container did not start again");
|
|
11277
12094
|
rejoinBuild(runtime, state, input.log);
|
|
11278
12095
|
const delivered = await redeliver(runtime, state, input.jobDir);
|
|
11279
12096
|
if (!delivered.ok) throw new Error(delivered.reason);
|
|
11280
12097
|
},
|
|
11281
12098
|
hashProgram: async () => {
|
|
11282
|
-
return await hashJudgeProgram((argv) => runtime.host.exec({ container: state.container, user: ADDED_USER, env:
|
|
12099
|
+
return await hashJudgeProgram((argv) => runtime.host.exec({ container: state.container, user: ADDED_USER, env: NO_ENV2, argv }), runtime.agents);
|
|
11283
12100
|
},
|
|
11284
12101
|
prepare: async (files, tree) => {
|
|
11285
12102
|
if (filesAreCopied(state)) {
|
|
@@ -11311,7 +12128,7 @@ function containerJudgeEnvironment(input) {
|
|
|
11311
12128
|
// The judge's files belong to the build's user, and Claude Code makes some of its folders private to it, so the runner's user cannot remove them from the
|
|
11312
12129
|
// host. Every capability is dropped in the container, so root there could not either; the build's user removes its own, and the runner removes the rest.
|
|
11313
12130
|
clear: async () => {
|
|
11314
|
-
const removed = await runtime.host.exec({ container: state.container, user, env:
|
|
12131
|
+
const removed = await runtime.host.exec({ container: state.container, user, env: NO_ENV2, argv: ["find", JUDGE_DIR, "-mindepth", "1", "-user", user, "-delete"] });
|
|
11315
12132
|
if (removed.status !== 0) throw new Error(`find exited ${removed.status}: ${firstLine(removed.stderr)}`);
|
|
11316
12133
|
if (!filesAreCopied(state)) return;
|
|
11317
12134
|
const emptied = await clearJudgeFolder(runtime, state, secretsOf(runtime, input.jobDir));
|
|
@@ -11416,7 +12233,7 @@ async function startCheckContainer(input) {
|
|
|
11416
12233
|
const started = await host.run(containerRunArgs({ ...runInput, network: state.network, home: state.home }, runtime.agents), { logPath });
|
|
11417
12234
|
if (started.status !== 0) return dockerFailed("starting the check environment's container", started);
|
|
11418
12235
|
if (transport === "exec") joinBuild(runtime, state, services, (line2) => log.line(`${tag} ${line2}`));
|
|
11419
|
-
if (!await
|
|
12236
|
+
if (!await waitForRelay2(runtime, state)) return fail("the relay in the check environment's container did not start");
|
|
11420
12237
|
const env = checkEnvironment({ config: claimCalls(config, job), item: job.item, repository, hostEnv: runtime.hostEnv, containerEnv: built.containerEnv ?? {} });
|
|
11421
12238
|
const secrets = () => tokens.issuedTokens();
|
|
11422
12239
|
let delivered = false;
|
|
@@ -11454,7 +12271,7 @@ async function startCheckContainer(input) {
|
|
|
11454
12271
|
return false;
|
|
11455
12272
|
}
|
|
11456
12273
|
const again = await host.start(name);
|
|
11457
|
-
if (again.status !== 0 || !await
|
|
12274
|
+
if (again.status !== 0 || !await waitForRelay2(runtime, state)) return false;
|
|
11458
12275
|
rejoinBuild(runtime, state, (line2) => log.line(`${tag} ${line2}`));
|
|
11459
12276
|
if (delivered) {
|
|
11460
12277
|
const again2 = await deliverInput();
|
|
@@ -11563,7 +12380,9 @@ function checksIn(root, log, tag) {
|
|
|
11563
12380
|
const policy = policyText === void 0 ? null : asHostReads({ path: POLICY_FILE, content: policyText }, base, log, tag);
|
|
11564
12381
|
const loaded = parsePolicy(policy, validatorFilesIn(root).map((file) => asHostReads(file, base, log, tag)));
|
|
11565
12382
|
for (const problem of loaded.problems) log.error(`${tag} ${problem.file}: ${problem.problem}`);
|
|
11566
|
-
const hostChecks = loaded.customs.filter(
|
|
12383
|
+
const hostChecks = loaded.customs.filter(
|
|
12384
|
+
(def) => def.runWhere === "host" && def.level !== "off" && def.declaresEmit !== null && def.declaresEmit !== CODE_REVIEW_NAME
|
|
12385
|
+
);
|
|
11567
12386
|
const checks = [];
|
|
11568
12387
|
for (const def of hostChecks) {
|
|
11569
12388
|
if (def.judge !== void 0) checks.push({ name: def.declaresEmit, judge: { brief: def.judge.brief, text: readBrief(root, def.judge.brief, log, tag), subjects: def.judge.subjects } });
|
|
@@ -11949,4 +12768,4 @@ async function runHostChecks(input) {
|
|
|
11949
12768
|
}
|
|
11950
12769
|
}
|
|
11951
12770
|
|
|
11952
|
-
export { ADOPTED_FETCH_RETRY_WINDOW_MS, ALREADY_RELEASED, AttemptLogBook, EXIT_CODE_FILE, GUEST_USAGE_INTERVAL_MS, HELPER_ENV, KIND_LABEL, LEASE_SECONDS, MAX_CHECK_ITEMS_BYTES, MICROVM_COMMAND_DIR, MIN_ENGINE_MAJOR, PLACEHOLDER_MARKER, RENEW_INTERVAL_SECONDS, RunnerInitError, agentCredentialCheck, appendCommandLog, attemptNote, checksIn, claimPermissionProblem, commandItems, commandLogOffset, containerCommandExec, createContainerRuntime, createHousekeepingDocker, createLeaseChannel, currentSkillCommand, decideHostBuildSkill, deliverCommitHooks, deliverContainerHooks, deliverExecMaven, deliverJobFiles, describeHookEnd, describeMachineDocker, detectMachine, ensureFirecrackerAndJailer, ensureNetworkReady, ensureTunnel, execArgv, execCommandLine, fetchManagedBuildSettings, fetchManagedClaudeKey, filesAreCopied, finishJob, foldSample, formerSkillProblem, formerSkillQueues, freeItemDisksUntil, gitRemoteFor, helperFirecrackerNote, helperSocketPath, holdManagedBuildSettings, holdManagedClaudeKey, hookLimitsFor, hostCommandEnvironment, hostEnvironment, housekeepingDockerIfReachable, inTeardown, installTrust, isContainerTracked, isGroupAlive, isIdle, isJudgeCheck, isMicroVmTracked, isPlaceholderCommand, isReadable, isTimedOut, isTracked, isUnfinished, itemScope, itemTag, jobEnv, jobRecordsClaim, judgeProbe, keepGhConfigCurrent, leaseExpiresAtMs, leaseTimeLeftMs, lifecycleFailureReason, lifecycleSteps, listAdoptableJobs, listItemDisks, listTrackedJobs, listUnreadableJobs, listenOnBroker, makeRecorder, managedBuildSettingsFor, measureDisk, microVmArchSupported, microVmAssetsPinned, microVmCommandLine, microVmOomKills, missingPermissionFix, missingPermissionOf, modellessProblem, modellessQueues, needsAgentCredential, needsBuildSkill, needsRenew, outcomeFromExitCode, parseCpuList, permissionModeProblem, permissionModeProblems, placeholderProblem, placeholderQueues, prepareBranch, prepareResume, prepareRunnerInit, probeCommand, probeHelper, probeMicroVmCommand, provisionContainer, provisionEnvironment, provisionMicroVm, reachDockerStep, readConfigObject, readCpuUsec, readDefinitions, readProvisionOut, readRecords, recoverLostJobs, releaseLease, removeOldestUntil, renewLease, resolveHostBuild, restartSender, restoreSessionIntoContainer, restoreSessionIntoMicroVm, retryFailedReleases, runCommand, runHook, runHostChecks, runHousekeeping, runRunnerInit, runWithSpawn, sampleGuest, savedStatesDir, scrubReason, serveLease, setStage, setUpRunnerCgroup, shellQuote, startHostServices, startMicroVmCommand, startSender, startServicesFor, stopOrphanedMicroVms, stoppedHelperReason, stripTerminalControls, supportsContainerBuilds, supportsMicroVmBuilds, sweepImageBuilders, testProofIn, timeoutAfter, unfinishedJobs, usableCpus, vmAlive, withTunnelLog, workdirProblem, writeGuestGhConfig, writeRunnerInit };
|
|
12771
|
+
export { ADOPTED_FETCH_RETRY_WINDOW_MS, ALREADY_RELEASED, AttemptLogBook, CRITERIA_CHECK, EXIT_CODE_FILE, GUEST_USAGE_INTERVAL_MS, HELPER_ENV, KIND_LABEL, LEASE_SECONDS, MAX_CHECK_ITEMS_BYTES, MICROVM_COMMAND_DIR, MIN_ENGINE_MAJOR, PLACEHOLDER_MARKER, RENEW_INTERVAL_SECONDS, RunnerInitError, SandboxGoneError, agentCredentialCheck, appendCommandLog, attemptNote, checksIn, claimPermissionProblem, commandItems, commandLogOffset, containerCommandExec, createContainerRuntime, createHousekeepingDocker, createLeaseChannel, currentSkillCommand, decideHostBuildSkill, deliverCommitHooks, deliverContainerHooks, deliverExecMaven, deliverJobFiles, deliverSandboxHooks, describeHookEnd, describeMachineDocker, detectMachine, ensureFirecrackerAndJailer, ensureNetworkReady, ensureTunnel, execArgv, execCommandLine, fetchManagedBuildSettings, fetchManagedClaudeKey, filesAreCopied, finishJob, foldSample, formerSkillProblem, formerSkillQueues, freeItemDisksUntil, gitRemoteFor, helperFirecrackerNote, helperSocketPath, holdManagedBuildSettings, holdManagedClaudeKey, hookLimitsFor, hostCommandEnvironment, hostEnvironment, housekeepingDockerIfReachable, inTeardown, installTrust, isContainerTracked, isGroupAlive, isIdle, isIsolatedJob, isJudgeCheck, isMicroVmTracked, isPlaceholderCommand, isReadable, isSandboxTracked, isTimedOut, isTracked, isUnfinished, itemScope, itemTag, jobEnv, jobRecordsClaim, judgeProbe, keepGhConfigCurrent, keptCommitsLine, leaseExpiresAtMs, leaseTimeLeftMs, lifecycleFailureReason, lifecycleSteps, listAdoptableJobs, listItemDisks, listTrackedJobs, listUnreadableJobs, listenOnBroker, makeRecorder, managedBuildSettingsFor, measureDisk, microVmArchSupported, microVmAssetsPinned, microVmCommandLine, microVmOomKills, missingPermissionFix, missingPermissionOf, modellessProblem, modellessQueues, needsAgentCredential, needsBuildSkill, needsRenew, outcomeFromExitCode, parseCpuList, permissionModeProblem, permissionModeProblems, placeholderProblem, placeholderQueues, prepareBranch, prepareResume, prepareRunnerInit, probeCommand, probeHelper, probeMicroVmCommand, probeSandboxCommand, provisionContainer, provisionEnvironment, provisionMicroVm, provisionSandbox, reachDockerStep, readConfigObject, readCpuUsec, readDefinitions, readProvisionOut, readRecords, recoverLostJobs, releaseLease, removeOldestUntil, renewLease, resolveHostBuild, restartSender, restoreSessionIntoContainer, restoreSessionIntoMicroVm, retryFailedReleases, runCommand, runHook, runHostChecks, runHousekeeping, runRunnerInit, runWithSpawn, sampleGuest, savedStatesDir, scrubReason, serveLease, setStage, setUpRunnerCgroup, shellQuote, startHostServices, startMicroVmCommand, startSandboxCommand, startSender, startServicesFor, stopOrphanedMicroVms, stoppedHelperReason, stripTerminalControls, supportsContainerBuilds, supportsMicroVmBuilds, sweepImageBuilders, sweepSandboxes, testProofIn, timeoutAfter, unfinishedJobs, usableCpus, vmAlive, withTunnelLog, workdirProblem, writeGuestGhConfig, writeRunnerInit };
|