@akanjs/devkit 3.2.0-rc.9 → 3.2.0
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/CHANGELOG.md +0 -529
- package/DEV_RUNTIME_KNOBS.md +4 -3
- package/README.ko.md +3 -2
- package/README.md +4 -2
- package/akanApp/BackendImportGraph.test.ts +1 -1
- package/akanApp/akanApp.host.test.ts +132 -3
- package/akanApp/akanApp.host.ts +146 -1216
- package/akanApp/akanApp.host.wiring.test.ts +727 -0
- package/akanApp/builderGap.ts +68 -0
- package/akanApp/builderRequestRelay.test.ts +93 -0
- package/akanApp/builderRequestRelay.ts +100 -0
- package/akanApp/builderRssRecycler.ts +182 -0
- package/akanApp/devBackend.ts +392 -0
- package/akanApp/devBuildStatusBoard.ts +128 -0
- package/akanApp/devBuilder.ts +196 -0
- package/akanApp/devIdleSuspend.test.ts +221 -0
- package/akanApp/devIdleSuspend.ts +192 -0
- package/akanApp/devIdleSuspend.watcher.test.ts +120 -0
- package/akanApp/devRecycler.test.ts +66 -0
- package/akanApp/devRecycler.ts +305 -0
- package/akanApp/processRss.ts +61 -0
- package/akanConfig/akanConfig.test.ts +45 -17
- package/akanConfig/akanConfig.ts +10 -10
- package/akanConfig/akanWorkspaceConfig.ts +1 -1
- package/akanConfig/productionLockfile.ts +1 -1
- package/apiReport/apiReport.test.ts +34 -3
- package/apiReport/apiReportDiff.ts +35 -1
- package/apiReport/apiReportPolicy.ts +3 -2
- package/{applicationBuildReporter.ts → app/applicationBuildReporter.ts} +2 -49
- package/{applicationBuildRunner.test.ts → app/applicationBuildRunner.test.ts} +71 -8
- package/{applicationBuildRunner.ts → app/applicationBuildRunner.ts} +60 -21
- package/{applicationTestPreload.ts → app/applicationTestPreload.ts} +1 -1
- package/{routeJsBudget.test.ts → app/routeJsBudget.test.ts} +17 -1
- package/{routeJsBudget.ts → app/routeJsBudget.ts} +9 -3
- package/{routeSourceValidator.test.ts → app/routeSourceValidator.test.ts} +17 -0
- package/{routeSourceValidator.ts → app/routeSourceValidator.ts} +5 -1
- package/artifact/implicitRootLayout.test.ts +71 -3
- package/artifact/implicitRootLayout.ts +9 -3
- package/artifact/implicitRootLayoutRender.test.tsx +297 -0
- package/biome.base.json +2 -1
- package/cloud/cloudApi.test.ts +1 -1
- package/cloud/configLock.test.ts +1 -1
- package/cloud/globalConfig.test.ts +1 -1
- package/cloud/globalConfig.ts +1 -1
- package/cloud/updatePackUpload.test.ts +1 -1
- package/codeAgent/agent/AkanCodeEnv.ts +1 -1
- package/codeAgent/agent/AkanCodeServices.ts +23 -0
- package/codeAgent/agent/akanCodePaths.ts +1 -1
- package/codeAgent/agent/akanCodeServices.test.ts +54 -0
- package/codeAgent/agent/akanSystemPrompt.ts +1 -1
- package/codeAgent/agent/codeAgent.test.ts +1 -1
- package/codeAgent/skills/akan-debug/SKILL.md +8 -5
- package/codeAgent/skills/akan-err/SKILL.md +7 -0
- package/codeAgent/skills/akan-mcp/SKILL.md +19 -1
- package/codeAgent/skills/akan-scaffold/SKILL.md +1 -1
- package/codeAgent/skills/akan-validate/SKILL.md +3 -3
- package/codeAgent/tools/AkanCli.ts +1 -1
- package/codeAgent/tools/AkanToolPack.ts +2 -2
- package/codeAgent/tools/akanCodePlugins.test.ts +1 -1
- package/commandDecorators/command.ts +35 -6
- package/commandDecorators/commandBuilder.ts +1 -1
- package/commandDecorators/commandDecorators.test.ts +107 -6
- package/commandDecorators/targetMeta.ts +2 -0
- package/commandDecorators/workspaceVersionCheck.test.ts +70 -1
- package/commandDecorators/workspaceVersionCheck.ts +64 -14
- package/context/akanContext.ts +576 -0
- package/context/akanContextInspection.ts +296 -0
- package/{akanMcpContract.test.ts → context/akanMcpContract.test.ts} +1 -1
- package/{akanMcpContract.ts → context/akanMcpContract.ts} +16 -256
- package/context/doctor/agentGuideCheck.ts +81 -0
- package/context/doctor/configLeftoverCheck.ts +35 -0
- package/context/doctor/doctorFindings.ts +70 -0
- package/context/doctor/generatedFreshness.ts +56 -0
- package/context/doctor/moduleShapeCheck.ts +88 -0
- package/context/doctor/recipeDuplicateCheck.ts +42 -0
- package/context/doctor/recipeIndexCheck.ts +87 -0
- package/context/doctor/rootShapeCheck.ts +55 -0
- package/context/doctor/workflowScope.ts +97 -0
- package/{recipeScanner.test.ts → context/recipeScanner.test.ts} +1 -1
- package/context/safeRead.ts +9 -0
- package/csrE2e/csrE2eHarness.fixture.ts +1 -1
- package/devkitUtils.test.ts +39 -5
- package/{apiReference.test.ts → docs/apiReference.test.ts} +4 -4
- package/{apiReference.ts → docs/apiReference.ts} +2 -2
- package/docs/errorCodeReference.test.ts +282 -0
- package/docs/errorCodeReference.ts +71 -0
- package/docs/errorCodeScan.ts +551 -0
- package/{frameworkGraph.test.ts → docs/frameworkGraph.test.ts} +1 -1
- package/executors/appExecutor.ts +448 -0
- package/executors/commandExecutionError.ts +53 -0
- package/executors/executor.ts +527 -0
- package/{executors.linkFallback.test.ts → executors/executors.linkFallback.test.ts} +1 -1
- package/{executors.test.ts → executors/executors.test.ts} +76 -15
- package/executors/index.ts +8 -0
- package/executors/libExecutor.ts +23 -0
- package/executors/moduleExecutor.ts +18 -0
- package/executors/pkgExecutor.ts +129 -0
- package/executors/sysExecutor.ts +301 -0
- package/executors/workspaceExecutor.ts +277 -0
- package/frontendBuild/allRoutesBuilder.test.ts +1 -1
- package/frontendBuild/autoImportSync.test.ts +1 -1
- package/frontendBuild/autoImportSync.ts +1 -1
- package/frontendBuild/buildRouteClient.test.ts +1 -1
- package/frontendBuild/clientEntriesBundler.test.ts +1 -1
- package/frontendBuild/csrArtifactBuilder.test.ts +1 -1
- package/frontendBuild/csrDevArtifactWriter.ts +1 -1
- package/frontendBuild/cssCompiler.test.ts +3 -2
- package/frontendBuild/devGeneratedIndexSync.test.ts +1 -1
- package/frontendBuild/devGeneratedIndexSync.ts +7 -38
- package/frontendBuild/dictionaryAssetBuilder.test.ts +1 -1
- package/frontendBuild/fontOptimizer.test.ts +1 -1
- package/frontendBuild/fontPruner.test.ts +1 -1
- package/frontendBuild/frontendBuild.test.ts +3 -3
- package/frontendBuild/hmrWatcher.stop.test.ts +63 -0
- package/frontendBuild/hmrWatcher.test.ts +1 -1
- package/frontendBuild/hmrWatcher.ts +22 -1
- package/frontendBuild/mcpAppViewBuilder.test.ts +1 -1
- package/frontendBuild/mcpAppViewBuilder.ts +1 -1
- package/frontendBuild/nativeCore.test.ts +1 -1
- package/frontendBuild/optionalPeers.test.ts +36 -8
- package/frontendBuild/pagesBundleBuilder.test.ts +2 -3
- package/frontendBuild/pagesBundleBuilder.ts +1 -1
- package/frontendBuild/precompressArtifacts.test.ts +1 -1
- package/frontendBuild/precompressArtifacts.ts +19 -6
- package/frontendBuild/serverGraphFile.ts +1 -1
- package/frontendBuild/sourceMtimeIndex.test.ts +1 -1
- package/frontendBuild/ssrDevBundler.test.ts +1 -1
- package/frontendBuild/vendorImportScanner.test.ts +1 -1
- package/frontendBuild/vendorNarrowing.test.ts +1 -1
- package/frontendBuild/watchRootResolver.test.ts +1 -1
- package/{agentAssets.test.ts → guideline/agentAssets.test.ts} +1 -1
- package/{agentAssets.ts → guideline/agentAssets.ts} +2 -2
- package/{agentsIndex.test.ts → guideline/agentsIndex.test.ts} +2 -2
- package/{agentsIndex.ts → guideline/agentsIndex.ts} +13 -10
- package/{conventionSet.test.ts → guideline/conventionSet.test.ts} +7 -4
- package/{conventionSet.ts → guideline/conventionSet.ts} +1 -1
- package/{prompter.ts → guideline/prompter.ts} +2 -3
- package/incrementalBuilder/buildBatch.proc.ts +14 -4
- package/incrementalBuilder/buildBatchProtocol.ts +2 -0
- package/incrementalBuilder/buildBatchRunner.test.ts +122 -2
- package/incrementalBuilder/buildBatchRunner.ts +17 -4
- package/incrementalBuilder/builderBoot.ts +106 -0
- package/incrementalBuilder/builderBuildStatus.ts +23 -0
- package/incrementalBuilder/builderChannel.test.ts +1 -1
- package/incrementalBuilder/builderChannel.ts +11 -0
- package/incrementalBuilder/builderGraphPayloads.ts +3 -3
- package/incrementalBuilder/builderLanes.ts +157 -0
- package/incrementalBuilder/builderWatch.ts +213 -0
- package/incrementalBuilder/csrRegistry.ts +234 -0
- package/incrementalBuilder/incrementalBuilder.proc.test.ts +101 -7
- package/incrementalBuilder/incrementalBuilder.proc.ts +81 -823
- package/incrementalBuilder/ssrRegistry.ts +282 -0
- package/index.ts +22 -22
- package/integration/devStability.integration.test.ts +62 -56
- package/integration/devStabilityHarness.test.ts +1 -1
- package/lint/__fixtures__/no-import-common-err/bad.tsx +13 -0
- package/lint/__fixtures__/no-import-common-err/good.tsx +12 -0
- package/{biomeBase.test.ts → lint/biomeBase.test.ts} +1 -1
- package/lint/gritRules.test.ts +1 -1
- package/{linter.test.ts → lint/linter.test.ts} +1 -1
- package/lint/no-import-common-err.grit +31 -0
- package/lint/no-init-fetch-in-client.grit +1 -1
- package/mobile/desktopBin.test.ts +1 -1
- package/mobile/desktopRelease.test.ts +1 -1
- package/mobile/desktopServerStage.test.ts +2 -2
- package/mobile/desktopServerStage.ts +1 -1
- package/mobile/nativeApi.test.ts +1 -1
- package/mobile/nativeApp.test.ts +1 -1
- package/mobile/nativeConfig.test.ts +1 -1
- package/mobile/nativePluginFolders.test.ts +1 -1
- package/mobile/nativePublicEnv.test.ts +1 -1
- package/mobile/nativeWebDir.test.ts +1 -1
- package/mobile/serverBundleSecrets.test.ts +1 -1
- package/mobile/tarWriter.test.ts +1 -1
- package/mobile/updatePackFolder.test.ts +1 -1
- package/package.json +173 -9
- package/packageExports.test.ts +20 -2
- package/piDependencyPins.test.ts +1 -1
- package/pipeline/PipelineDefinition.ts +1 -1
- package/platformTest/IdleWatchedProcess.test.ts +1 -1
- package/platformTest/LinuxDockerTarget.ts +1 -1
- package/platformTest/PlatformTestRun.test.ts +1 -1
- package/platformTest/TestSnapshot.test.ts +1 -1
- package/platformTest/WindowsSshTarget.ts +1 -1
- package/preview/previewView.test.ts +23 -1
- package/{abstractDoc.test.ts → quality/abstractDoc.test.ts} +2 -2
- package/{abstractDoc.ts → quality/abstractDoc.ts} +1 -1
- package/quality/bareErrorScanner.ts +126 -0
- package/{maintainabilityBaseline.test.ts → quality/maintainabilityBaseline.test.ts} +73 -0
- package/{maintainabilityBaseline.ts → quality/maintainabilityBaseline.ts} +97 -9
- package/{maintainabilityContract.test.ts → quality/maintainabilityContract.test.ts} +383 -2
- package/{maintainabilityContract.ts → quality/maintainabilityContract.ts} +151 -29
- package/{maintainabilityExceptionScanner.test.ts → quality/maintainabilityExceptionScanner.test.ts} +15 -1
- package/{maintainabilityExceptionScanner.ts → quality/maintainabilityExceptionScanner.ts} +5 -1
- package/{maintainabilityLimits.ts → quality/maintainabilityLimits.ts} +12 -0
- package/{maintainabilityReport.ts → quality/maintainabilityReport.ts} +20 -3
- package/{qualityScanner.test.ts → quality/qualityScanner.test.ts} +41 -1
- package/{qualityScanner.ts → quality/qualityScanner.ts} +25 -91
- package/{storeAccessScanner.ts → quality/storeAccessScanner.ts} +15 -2
- package/quality/workspaceSourceFiles.ts +82 -0
- package/{subspace.test.ts → subspace/subspace.test.ts} +25 -4
- package/{subspace.ts → subspace/subspace.ts} +5 -5
- package/{subspaceClone.ts → subspace/subspaceClone.ts} +8 -8
- package/{subspaceConfig.ts → subspace/subspaceConfig.ts} +5 -1
- package/{testHelpers.ts → test/testHelpers.ts} +37 -1
- package/transforms/barrelAnalyzer.ts +31 -10
- package/transforms/browserDirnamePlugin.test.ts +1 -1
- package/transforms/externalizeFrameworkPlugin.test.ts +1 -1
- package/transforms/mcpAppPageTrimmer.test.ts +1 -1
- package/transforms/pureLazyMarker.test.ts +1 -1
- package/transforms/serverEnvPlugin.test.ts +1 -1
- package/transforms/serverEnvProfile.test.ts +1 -1
- package/transforms/sideEffectImportOrder.test.ts +1 -1
- package/transforms/transforms.test.ts +52 -2
- package/transforms/tsconfigPackageResolver.test.ts +1 -1
- package/{createTunnel.test.ts → tunnel/createTunnel.test.ts} +1 -1
- package/{createTunnel.ts → tunnel/createTunnel.ts} +2 -2
- package/{sshHostKeys.ts → tunnel/sshHostKeys.ts} +2 -2
- package/typecheck/projectTypecheck.test.ts +23 -1
- package/typecheck/projectTypecheck.ts +10 -2
- package/{typeChecker.test.ts → typecheck/typeChecker.test.ts} +1 -1
- package/{typeChecker.ts → typecheck/typeChecker.ts} +5 -4
- package/typecheck/typecheck.proc.ts +6 -2
- package/typecheck/typecheckFailure.ts +1 -1
- package/util/errorReport.ts +66 -0
- package/{jsonFormatter.test.ts → util/jsonFormatter.test.ts} +1 -1
- package/workflow/constantSource.ts +187 -0
- package/workflow/dictionarySource.ts +184 -0
- package/workflow/executor.ts +6 -9
- package/workflow/fieldExpression.ts +153 -0
- package/workflow/fieldLabel.ts +61 -0
- package/workflow/fieldOrder.ts +117 -0
- package/workflow/fieldType.ts +2 -1
- package/workflow/guardCatalog.test.ts +1 -1
- package/workflow/keyRename.ts +1 -1
- package/workflow/moduleIndex.test.ts +2 -2
- package/workflow/moduleIndex.ts +2 -2
- package/workflow/modulePaths.ts +27 -0
- package/workflow/mutationScaffold.ts +7 -15
- package/workflow/mutationSource.ts +2 -1
- package/workflow/plan.ts +2 -1
- package/workflow/primitiveReport.ts +78 -0
- package/workflow/rolloutGate.test.ts +1 -1
- package/workflow/rolloutGate.ts +1 -1
- package/workflow/serviceSource.ts +33 -0
- package/workflow/signalSource.ts +96 -0
- package/workflow/source.ts +50 -1100
- package/workflow/sourceAst.ts +30 -0
- package/workflow/sourceImports.ts +105 -0
- package/workflow/sourceText.ts +13 -0
- package/workflow/templateSource.ts +30 -0
- package/workflow/testSource.ts +31 -0
- package/workflow/types.ts +1 -1
- package/workflow/uiPolicy.ts +1 -1
- package/{appSelectionMemory.ts → workspace/appSelectionMemory.ts} +1 -1
- package/{codegenLock.test.ts → workspace/codegenLock.test.ts} +1 -1
- package/{dependencyScanner.test.ts → workspace/dependencyScanner.test.ts} +1 -1
- package/{dependencyScanner.ts → workspace/dependencyScanner.ts} +2 -2
- package/{envSeed.test.ts → workspace/envSeed.test.ts} +2 -2
- package/{envSeed.ts → workspace/envSeed.ts} +1 -1
- package/{libSource.test.ts → workspace/libSource.test.ts} +2 -2
- package/{libSource.ts → workspace/libSource.ts} +1 -1
- package/{scanInfo.ts → workspace/scanInfo.ts} +21 -10
- package/{slicePlanner.test.ts → workspace/slicePlanner.test.ts} +2 -2
- package/{slicePlanner.ts → workspace/slicePlanner.ts} +1 -1
- package/{workspaceGraph.test.ts → workspace/workspaceGraph.test.ts} +1 -1
- package/{workspaceGraph.ts → workspace/workspaceGraph.ts} +1 -1
- package/{workspaceLayout.test.ts → workspace/workspaceLayout.test.ts} +1 -1
- package/{workspaceLayout.ts → workspace/workspaceLayout.ts} +3 -1
- package/akanContext.ts +0 -1083
- package/executors.ts +0 -1749
- /package/{applicationBuildReporter.test.ts → app/applicationBuildReporter.test.ts} +0 -0
- /package/{akanMcpToolError.ts → context/akanMcpToolError.ts} +0 -0
- /package/{moduleFieldNames.test.ts → context/moduleFieldNames.test.ts} +0 -0
- /package/{moduleFieldNames.ts → context/moduleFieldNames.ts} +0 -0
- /package/{recipeScanner.ts → context/recipeScanner.ts} +0 -0
- /package/{declarationReader.ts → docs/declarationReader.ts} +0 -0
- /package/{frameworkGraph.ts → docs/frameworkGraph.ts} +0 -0
- /package/{biomeBase.ts → lint/biomeBase.ts} +0 -0
- /package/{linter.ts → lint/linter.ts} +0 -0
- /package/{commentDensityScanner.test.ts → quality/commentDensityScanner.test.ts} +0 -0
- /package/{commentDensityScanner.ts → quality/commentDensityScanner.ts} +0 -0
- /package/{componentSizeScanner.test.ts → quality/componentSizeScanner.test.ts} +0 -0
- /package/{componentSizeScanner.ts → quality/componentSizeScanner.ts} +0 -0
- /package/{componentWriteChainScanner.test.ts → quality/componentWriteChainScanner.test.ts} +0 -0
- /package/{componentWriteChainScanner.ts → quality/componentWriteChainScanner.ts} +0 -0
- /package/{deprecatedCommentScanner.test.ts → quality/deprecatedCommentScanner.test.ts} +0 -0
- /package/{deprecatedCommentScanner.ts → quality/deprecatedCommentScanner.ts} +0 -0
- /package/{endpointReach.test.ts → quality/endpointReach.test.ts} +0 -0
- /package/{endpointReach.ts → quality/endpointReach.ts} +0 -0
- /package/{formSetterScanner.test.ts → quality/formSetterScanner.test.ts} +0 -0
- /package/{formSetterScanner.ts → quality/formSetterScanner.ts} +0 -0
- /package/{kindBranchScanner.test.ts → quality/kindBranchScanner.test.ts} +0 -0
- /package/{kindBranchScanner.ts → quality/kindBranchScanner.ts} +0 -0
- /package/{maintainabilityReport.test.ts → quality/maintainabilityReport.test.ts} +0 -0
- /package/{renderMutationScanner.test.ts → quality/renderMutationScanner.test.ts} +0 -0
- /package/{renderMutationScanner.ts → quality/renderMutationScanner.ts} +0 -0
- /package/{serviceLoopCallScanner.test.ts → quality/serviceLoopCallScanner.test.ts} +0 -0
- /package/{serviceLoopCallScanner.ts → quality/serviceLoopCallScanner.ts} +0 -0
- /package/{signalMutationIndex.test.ts → quality/signalMutationIndex.test.ts} +0 -0
- /package/{signalMutationIndex.ts → quality/signalMutationIndex.ts} +0 -0
- /package/{sourceComments.test.ts → quality/sourceComments.test.ts} +0 -0
- /package/{sourceComments.ts → quality/sourceComments.ts} +0 -0
- /package/{ssrScanner.test.ts → quality/ssrScanner.test.ts} +0 -0
- /package/{ssrScanner.ts → quality/ssrScanner.ts} +0 -0
- /package/{storeAccessScanner.test.ts → quality/storeAccessScanner.test.ts} +0 -0
- /package/{storeSource.ts → quality/storeSource.ts} +0 -0
- /package/{storeWriteScanner.test.ts → quality/storeWriteScanner.test.ts} +0 -0
- /package/{storeWriteScanner.ts → quality/storeWriteScanner.ts} +0 -0
- /package/{structureScanner.test.ts → quality/structureScanner.test.ts} +0 -0
- /package/{structureScanner.ts → quality/structureScanner.ts} +0 -0
- /package/{testOnlyExportScanner.test.ts → quality/testOnlyExportScanner.test.ts} +0 -0
- /package/{testOnlyExportScanner.ts → quality/testOnlyExportScanner.ts} +0 -0
- /package/{writePath.test.ts → quality/writePath.test.ts} +0 -0
- /package/{writePath.ts → quality/writePath.ts} +0 -0
- /package/{writePlacementScanner.test.ts → quality/writePlacementScanner.test.ts} +0 -0
- /package/{writePlacementScanner.ts → quality/writePlacementScanner.ts} +0 -0
- /package/{writingActionIndex.test.ts → quality/writingActionIndex.test.ts} +0 -0
- /package/{writingActionIndex.ts → quality/writingActionIndex.ts} +0 -0
- /package/{subspaceReport.ts → subspace/subspaceReport.ts} +0 -0
- /package/{sshTunnel.ts → tunnel/sshTunnel.ts} +0 -0
- /package/{fileEditor.ts → util/fileEditor.ts} +0 -0
- /package/{fileSys.test.ts → util/fileSys.test.ts} +0 -0
- /package/{fileSys.ts → util/fileSys.ts} +0 -0
- /package/{jsonFormatter.ts → util/jsonFormatter.ts} +0 -0
- /package/{selectModel.ts → util/selectModel.ts} +0 -0
- /package/{semver.test.ts → util/semver.test.ts} +0 -0
- /package/{semver.ts → util/semver.ts} +0 -0
- /package/{shellOnlyEnv.test.ts → util/shellOnlyEnv.test.ts} +0 -0
- /package/{shellOnlyEnv.ts → util/shellOnlyEnv.ts} +0 -0
- /package/{spinner.test.ts → util/spinner.test.ts} +0 -0
- /package/{spinner.ts → util/spinner.ts} +0 -0
- /package/{stripAnsi.ts → util/stripAnsi.ts} +0 -0
- /package/{codegenLock.ts → workspace/codegenLock.ts} +0 -0
- /package/{getRelatedCnsts.ts → workspace/getRelatedCnsts.ts} +0 -0
- /package/{gitRevision.test.ts → workspace/gitRevision.test.ts} +0 -0
- /package/{gitRevision.ts → workspace/gitRevision.ts} +0 -0
- /package/{manifestDependencies.ts → workspace/manifestDependencies.ts} +0 -0
- /package/{packageExportsMap.ts → workspace/packageExportsMap.ts} +0 -0
- /package/{repoIdentity.ts → workspace/repoIdentity.ts} +0 -0
- /package/{types.ts → workspace/types.ts} +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { describe, expect, test } from "bun:test";
|
|
2
2
|
import path from "node:path";
|
|
3
|
-
import { tempDirs, writeText as write } from "../testHelpers";
|
|
3
|
+
import { tempDirs, writeText as write } from "../test/testHelpers";
|
|
4
4
|
import { resolveSsrPageEntries } from "./implicitRootLayout";
|
|
5
5
|
|
|
6
6
|
const makeTempRoot = tempDirs("akan-implicit-root-layout-");
|
|
@@ -53,11 +53,74 @@ describe("resolveSsrPageEntries", () => {
|
|
|
53
53
|
// Its guard runs from that level too, ahead of this one, and an MCP view takes its providers from there.
|
|
54
54
|
expect(generatedSource).toContain("export const guard = userLayout.guard;");
|
|
55
55
|
expect(generatedSource).not.toContain("McpAppRoot");
|
|
56
|
+
expect(generatedSource).not.toContain("LevelBoundary");
|
|
56
57
|
expect(generatedSource).toContain(
|
|
57
58
|
"<UserLayout params={params} searchParams={searchParams}>{children}</UserLayout>",
|
|
58
59
|
);
|
|
59
60
|
});
|
|
60
61
|
|
|
62
|
+
test("bounds the System root layout's own content inside System.Provider, for a server render only", async () => {
|
|
63
|
+
const appRoot = await makeTempRoot();
|
|
64
|
+
await write(path.join(appRoot, "env", "env.client.ts"), "export const env = {};\n");
|
|
65
|
+
await write(
|
|
66
|
+
path.join(appRoot, "page", "_layout.tsx"),
|
|
67
|
+
"export default function Layout({ children }) { return children; }\n",
|
|
68
|
+
);
|
|
69
|
+
await write(
|
|
70
|
+
path.join(appRoot, "page", "(home)", "_layout.tsx"),
|
|
71
|
+
"export default function Layout({ children }) { return children; }\n",
|
|
72
|
+
);
|
|
73
|
+
|
|
74
|
+
const entries = await resolveSsrPageEntries({
|
|
75
|
+
appCwdPath: appRoot,
|
|
76
|
+
appName: "demo",
|
|
77
|
+
pageKeys: ["./_layout.tsx", "./(home)/_layout.tsx", "./(home)/_index.tsx"],
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
const source = await Bun.file(
|
|
81
|
+
entries.find((entry) => entry.key === "./__root_layout.tsx")?.moduleAbsPath ?? "",
|
|
82
|
+
).text();
|
|
83
|
+
expect(source).toContain('import { RouteLevelBoundary } from "akanjs/webkit/RouteLevelBoundary.tsx";');
|
|
84
|
+
expect(source).toContain(
|
|
85
|
+
" const layout = <UserLayout params={params} searchParams={searchParams}>{children}</UserLayout>;\n return (\n <System.Provider",
|
|
86
|
+
);
|
|
87
|
+
expect(source).toContain(
|
|
88
|
+
' >\n {process.env.AKAN_PUBLIC_RENDER_ENV === "csr" ? layout : <RouteLevelBoundary>{layout}</RouteLevelBoundary>}\n </System.Provider>',
|
|
89
|
+
);
|
|
90
|
+
expect(source.match(/<RouteLevelBoundary>/g)).toHaveLength(1);
|
|
91
|
+
expect(source.slice(source.indexOf("export function McpAppRoot"))).not.toContain("RouteLevelBoundary");
|
|
92
|
+
|
|
93
|
+
const nested = await Bun.file(
|
|
94
|
+
entries.find((entry) => entry.key === "./(home)/__root_layout.tsx")?.moduleAbsPath ?? "",
|
|
95
|
+
).text();
|
|
96
|
+
expect(nested).not.toContain("RouteLevelBoundary");
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
test("leaves the boundary out of a CSR build, which an MCP App view's namespace import of the layout shares", async () => {
|
|
100
|
+
const appRoot = await makeTempRoot();
|
|
101
|
+
await write(path.join(appRoot, "env", "env.client.ts"), "export const env = {};\n");
|
|
102
|
+
await write(path.join(appRoot, "page", "_layout.tsx"), "export default ({ children }) => children;\n");
|
|
103
|
+
const entries = await resolveSsrPageEntries({
|
|
104
|
+
appCwdPath: appRoot,
|
|
105
|
+
appName: "demo",
|
|
106
|
+
pageKeys: ["./_layout.tsx", "./_index.tsx"],
|
|
107
|
+
});
|
|
108
|
+
const source = await Bun.file(
|
|
109
|
+
entries.find((entry) => entry.key === "./__root_layout.tsx")?.moduleAbsPath ?? "",
|
|
110
|
+
).text();
|
|
111
|
+
const compiled = (renderEnv: "csr" | "ssr") =>
|
|
112
|
+
new Bun.Transpiler({
|
|
113
|
+
loader: "tsx",
|
|
114
|
+
define: { "process.env.AKAN_PUBLIC_RENDER_ENV": JSON.stringify(renderEnv) },
|
|
115
|
+
trimUnusedImports: true,
|
|
116
|
+
}).transformSync(source);
|
|
117
|
+
|
|
118
|
+
expect(compiled("csr")).toContain("export const LevelBoundary = undefined;");
|
|
119
|
+
expect(compiled("csr")).not.toMatch(/\bRouteLevelBoundary\b(?!\.tsx)/);
|
|
120
|
+
expect(compiled("ssr")).toContain("export const LevelBoundary = RouteLevelBoundary;");
|
|
121
|
+
expect(compiled("ssr")).toMatch(/import \{ ?RouteLevelBoundary ?\} from "akanjs\/webkit\/RouteLevelBoundary\.tsx"/);
|
|
122
|
+
});
|
|
123
|
+
|
|
61
124
|
test("keeps system provider for grouped root boundaries without an ancestor root", async () => {
|
|
62
125
|
const appRoot = await makeTempRoot();
|
|
63
126
|
const pageRoot = path.join(appRoot, "page");
|
|
@@ -87,6 +150,9 @@ describe("resolveSsrPageEntries", () => {
|
|
|
87
150
|
);
|
|
88
151
|
expect(generatedSource).toContain("export function McpAppRoot({ children, params, path }: McpAppRootProps) {");
|
|
89
152
|
expect(generatedSource).toContain("<System.App");
|
|
153
|
+
expect(generatedSource).toContain(
|
|
154
|
+
'export const LevelBoundary = process.env.AKAN_PUBLIC_RENDER_ENV === "csr" ? undefined : RouteLevelBoundary;',
|
|
155
|
+
);
|
|
90
156
|
expect(generatedSource).toContain('import { allDictionary } from "../dict/useDict.ts";');
|
|
91
157
|
expect(generatedSource).toContain(
|
|
92
158
|
'allDictionary={process.env.AKAN_PUBLIC_RENDER_ENV === "ssr" ? allDictionary : undefined}',
|
|
@@ -170,7 +236,9 @@ describe("resolveSsrPageEntries", () => {
|
|
|
170
236
|
expect(userSource).toContain('process.env.AKAN_PUBLIC_RENDER_ENV === "csr"');
|
|
171
237
|
expect(userSource).toContain("? await UserLayout({ params, searchParams, children })");
|
|
172
238
|
expect(userSource).toContain(": <UserLayout params={params} searchParams={searchParams}>{children}</UserLayout>;");
|
|
173
|
-
expect(userSource).toContain(
|
|
239
|
+
expect(userSource).toContain(
|
|
240
|
+
' {process.env.AKAN_PUBLIC_RENDER_ENV === "csr" ? layout : <RouteLevelBoundary>{layout}</RouteLevelBoundary>}\n </System.Provider>',
|
|
241
|
+
);
|
|
174
242
|
|
|
175
243
|
const signRoot = entries.find((entry) => entry.key === "./(sign)/__root_layout.tsx");
|
|
176
244
|
const signSource = await Bun.file(signRoot?.moduleAbsPath ?? "").text();
|
|
@@ -178,7 +246,7 @@ describe("resolveSsrPageEntries", () => {
|
|
|
178
246
|
expect(signSource).toContain("export default function GeneratedLayout(");
|
|
179
247
|
expect(signSource).not.toContain("await UserLayout(");
|
|
180
248
|
expect(signSource).toContain(
|
|
181
|
-
"
|
|
249
|
+
" const layout = <UserLayout params={params} searchParams={searchParams}>{children}</UserLayout>;\n",
|
|
182
250
|
);
|
|
183
251
|
});
|
|
184
252
|
|
|
@@ -199,8 +199,9 @@ async function writeGeneratedRootLayoutFile(opts: {
|
|
|
199
199
|
? await UserLayout({ params, searchParams, children })
|
|
200
200
|
: ${userLayoutElement};
|
|
201
201
|
`
|
|
202
|
-
:
|
|
203
|
-
const
|
|
202
|
+
: opts.includeSystemProvider
|
|
203
|
+
? ` const layout = ${userLayoutElement};\n`
|
|
204
|
+
: "";
|
|
204
205
|
const layoutReturn = isAsyncUserLayout ? "layout" : userLayoutElement;
|
|
205
206
|
//? Under an ancestor root boundary the route tree merges that root's head itself; merging it here would repeat it.
|
|
206
207
|
const headLayouts = opts.includeSystemProvider ? "[inheritedLayout, userLayout]" : "[userLayout]";
|
|
@@ -225,12 +226,16 @@ ${layoutSignature}({ children, params, searchParams }: LayoutProps) {
|
|
|
225
226
|
${layoutBinding} return `;
|
|
226
227
|
//? System from its file, not the barrel: a dev registry compiles every module the barrel names, and with them the
|
|
227
228
|
//? optional peers (react-icons) an app drawing none of those components never installs.
|
|
229
|
+
//? The root level's boundary sits inside System.Provider, beside the bridge that starts the router its retry calls.
|
|
230
|
+
//? A CSR render has none: RenderLayer draws a failed level there, and a route control also carries a digest.
|
|
231
|
+
//? Its export is undefined there too, so the `import * as root` of an MCP App view, built as CSR, drops it.
|
|
228
232
|
const source = opts.includeSystemProvider
|
|
229
233
|
? `import type { LayoutModule, LayoutProps, PageProps } from "akanjs/client";
|
|
230
234
|
import { assertGuardOnChain, loadFonts, RouteGuards, resolveRouteModule, RouteHead } from "akanjs/client";
|
|
231
235
|
import type { ReactNode } from "react";
|
|
232
236
|
import { System } from "${ROOT_LAYOUT_SYSTEM.specifier}";
|
|
233
237
|
import type { McpAppRootProps } from "akanjs/webkit";
|
|
238
|
+
import { RouteLevelBoundary } from "akanjs/webkit/RouteLevelBoundary.tsx";
|
|
234
239
|
import { env } from "@apps/${opts.appName}/env/env.client";
|
|
235
240
|
import { allDictionary } from ${JSON.stringify(dictMacroSpecifier)};
|
|
236
241
|
${storeImport}${inheritedImport}${userImport}
|
|
@@ -242,6 +247,7 @@ const defaultFontClassName = defaultFont ? (defaultFont.className ?? \`font-\${d
|
|
|
242
247
|
export const theme = userLayout.theme ?? inheritedLayout.theme;
|
|
243
248
|
export const viewport = userLayout.viewport ?? inheritedLayout.viewport;
|
|
244
249
|
export const manifest = userLayout.manifest ?? inheritedLayout.manifest;
|
|
250
|
+
export const LevelBoundary = process.env.AKAN_PUBLIC_RENDER_ENV === "csr" ? undefined : RouteLevelBoundary;
|
|
245
251
|
|
|
246
252
|
${layoutExports}(
|
|
247
253
|
<System.Provider
|
|
@@ -259,7 +265,7 @@ ${layoutExports}(
|
|
|
259
265
|
wsConnect={userLayout.wsConnect ?? inheritedLayout.wsConnect}
|
|
260
266
|
allDictionary={process.env.AKAN_PUBLIC_RENDER_ENV === "ssr" ? allDictionary : undefined}
|
|
261
267
|
>
|
|
262
|
-
|
|
268
|
+
{process.env.AKAN_PUBLIC_RENDER_ENV === "csr" ? layout : <RouteLevelBoundary>{layout}</RouteLevelBoundary>}
|
|
263
269
|
</System.Provider>
|
|
264
270
|
);
|
|
265
271
|
}
|
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
import { describe, expect, spyOn, test } from "bun:test";
|
|
2
|
+
import { mkdir, readdir, rm, symlink } from "node:fs/promises";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { Readable } from "node:stream";
|
|
5
|
+
import { act, Children, createElement, Fragment, isValidElement, type ReactElement, type ReactNode } from "react";
|
|
6
|
+
import { renderToReadableStream } from "react-dom/server.edge";
|
|
7
|
+
import { createFromNodeStream } from "react-server-dom-webpack/client.node";
|
|
8
|
+
import { PagesBundleBuilder } from "../frontendBuild/pagesBundleBuilder";
|
|
9
|
+
import { tempDirs, writeText as write } from "../test/testHelpers";
|
|
10
|
+
import { resolveSsrPageEntries } from "./implicitRootLayout";
|
|
11
|
+
|
|
12
|
+
Object.assign(process.env, {
|
|
13
|
+
AKAN_PUBLIC_APP_NAME: "demo",
|
|
14
|
+
AKAN_PUBLIC_REPO_NAME: "demo",
|
|
15
|
+
AKAN_PUBLIC_SERVE_DOMAIN: "localhost",
|
|
16
|
+
AKAN_PUBLIC_ENV: "testing",
|
|
17
|
+
AKAN_PUBLIC_OPERATION_MODE: "cloud",
|
|
18
|
+
});
|
|
19
|
+
const akanjsRoot = path.resolve(import.meta.dir, "../../../akanjs");
|
|
20
|
+
process.env.AKAN_RSC_WORKER_PATH = path.join(akanjsRoot, "server/rscWorker.tsx");
|
|
21
|
+
const { RscWorker } = await import("akanjs/server/rscWorkerHost.ts");
|
|
22
|
+
const { SsrFromRscRenderer } = await import("akanjs/server/ssrFromRscRenderer.tsx");
|
|
23
|
+
const { resetEnvCache } = await import("akanjs/base");
|
|
24
|
+
const { Logger } = await import("akanjs/common");
|
|
25
|
+
const { makePageProto, registerClientRuntime, router } = await import("akanjs/client");
|
|
26
|
+
//? What the app's client bundle registers in a browser; the hydrated System.Provider reads it.
|
|
27
|
+
const socket = { connect: () => undefined, connectOnUse: () => undefined };
|
|
28
|
+
registerClientRuntime({ ...makePageProto({ en: {} }), fetch: { instance: socket } } as never);
|
|
29
|
+
|
|
30
|
+
const makeTempRoot = tempDirs("akan-root-level-render-");
|
|
31
|
+
const boundedLayout = "<RouteLevelBoundary>{layout}</RouteLevelBoundary>";
|
|
32
|
+
const pageSource = 'import { page } from "akanjs/client";\nexport default page().render(() => <p>page</p>);\n';
|
|
33
|
+
const idsLayoutSource = `import { rootLayout } from "akanjs/client";
|
|
34
|
+
import { UsesId } from "../usesId";
|
|
35
|
+
export default rootLayout().render(({ children }) => <section id="user"><UsesId />{children}</section>);
|
|
36
|
+
`;
|
|
37
|
+
//? Throws only once the test has read the shell's body, so the boundary streams pending whatever the payload's size.
|
|
38
|
+
const lateLayoutSource = `import { rootLayout } from "akanjs/client";
|
|
39
|
+
export default rootLayout()
|
|
40
|
+
.loading(() => <i>root loading</i>)
|
|
41
|
+
.render(async () => {
|
|
42
|
+
while (!(await Bun.file(process.env.AKAN_TEST_SHELL_READ ?? "").exists())) await Bun.sleep(5);
|
|
43
|
+
throw new Error("root layout broke");
|
|
44
|
+
});
|
|
45
|
+
`;
|
|
46
|
+
|
|
47
|
+
const linkPackage = async (root: string, name: string, dir: string) => {
|
|
48
|
+
await mkdir(path.dirname(path.join(root, "node_modules", name)), { recursive: true });
|
|
49
|
+
await symlink(dir, path.join(root, "node_modules", name));
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
const writeApp = async (routes: Record<string, string>) => {
|
|
53
|
+
const root = await makeTempRoot();
|
|
54
|
+
const appDir = path.join(root, "apps/demo");
|
|
55
|
+
await linkPackage(root, "akanjs", akanjsRoot);
|
|
56
|
+
for (const name of ["react", "react-dom", "react-server-dom-webpack"])
|
|
57
|
+
await linkPackage(root, name, path.dirname(Bun.resolveSync(`${name}/package.json`, akanjsRoot)));
|
|
58
|
+
await write(
|
|
59
|
+
path.join(root, "tsconfig.json"),
|
|
60
|
+
JSON.stringify({ compilerOptions: { paths: { "@apps/*": ["./apps/*"] } } }),
|
|
61
|
+
);
|
|
62
|
+
await write(path.join(appDir, "env/env.client.ts"), "export const env = {};\n");
|
|
63
|
+
await write(path.join(appDir, "lib/dict.ts"), "export const getAllDictionary = () => ({});\n");
|
|
64
|
+
//? With lib/st.ts present the generated layout imports both, and the worker's System.Provider reads this runtime.
|
|
65
|
+
await write(
|
|
66
|
+
path.join(appDir, "lib/useClient.ts"),
|
|
67
|
+
'import { makePageProto, registerClientRuntime } from "akanjs/client";\nregisterClientRuntime(makePageProto({}) as never);\n',
|
|
68
|
+
);
|
|
69
|
+
await write(path.join(appDir, "lib/st.ts"), "export {};\n");
|
|
70
|
+
await write(
|
|
71
|
+
path.join(appDir, "page/usesId.tsx"),
|
|
72
|
+
'"use client";\nimport { useId } from "react";\nexport const UsesId = () => <b id={useId()}>uses id</b>;\n',
|
|
73
|
+
);
|
|
74
|
+
for (const [file, source] of Object.entries(routes)) await write(path.join(appDir, "page", file), source);
|
|
75
|
+
return { root, appDir, pageKeys: Object.keys(routes).map((file) => `./${file}`) };
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
//? Each client reference's stub names its workspace-relative path in the error it throws when called on the server.
|
|
79
|
+
const clientReferenceIds = async (serverDir: string) => {
|
|
80
|
+
const ids = new Set<string>();
|
|
81
|
+
for (const file of await readdir(serverDir, { recursive: true })) {
|
|
82
|
+
if (!file.endsWith(".js")) continue;
|
|
83
|
+
const source = await Bun.file(path.join(serverDir, file)).text();
|
|
84
|
+
for (const [, id] of source.matchAll(/Attempted to call '[^']+' from '([^']+)' on the server/g))
|
|
85
|
+
if (id) ids.add(id);
|
|
86
|
+
}
|
|
87
|
+
return [...ids];
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
const ssrManifest: { moduleLoading: null; moduleMap: Record<string, unknown> } = { moduleLoading: null, moduleMap: {} };
|
|
91
|
+
|
|
92
|
+
const readHtml = async (stream: ReadableStream<Uint8Array>, onBody: () => Promise<unknown>) => {
|
|
93
|
+
const reader = stream.getReader();
|
|
94
|
+
const decoder = new TextDecoder();
|
|
95
|
+
let html = "";
|
|
96
|
+
let bodyRead = false;
|
|
97
|
+
for (;;) {
|
|
98
|
+
const { value, done } = await reader.read();
|
|
99
|
+
if (done) return html + decoder.decode();
|
|
100
|
+
html += decoder.decode(value, { stream: true });
|
|
101
|
+
if (bodyRead || !html.includes("<body")) continue;
|
|
102
|
+
bodyRead = true;
|
|
103
|
+
await onBody();
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
interface Rendered {
|
|
108
|
+
html: string;
|
|
109
|
+
status: number;
|
|
110
|
+
payload: Uint8Array;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
const withBuiltPages = async (
|
|
114
|
+
{ routes, unbounded }: { routes: Record<string, string>; unbounded?: string },
|
|
115
|
+
run: (render: (route: string) => Promise<Rendered>) => Promise<void>,
|
|
116
|
+
) => {
|
|
117
|
+
const { root, appDir, pageKeys } = await writeApp(routes);
|
|
118
|
+
const app = {
|
|
119
|
+
name: "demo",
|
|
120
|
+
cwdPath: appDir,
|
|
121
|
+
dist: { cwdPath: path.join(root, "dist/apps/demo") },
|
|
122
|
+
workspace: { workspaceRoot: root },
|
|
123
|
+
getConfig: async () => ({ basePaths: [], barrelImports: [], externalLibs: [] }),
|
|
124
|
+
getTsConfig: async () => ({ compilerOptions: { paths: { "@apps/*": ["./apps/*"] } } }),
|
|
125
|
+
getPublicEnv: () => ({}),
|
|
126
|
+
verbose: () => undefined,
|
|
127
|
+
};
|
|
128
|
+
const entries = await resolveSsrPageEntries({ appCwdPath: appDir, appName: "demo", pageKeys });
|
|
129
|
+
if (unbounded) {
|
|
130
|
+
const generated = entries.find((entry) => entry.key === `./${unbounded}/__root_layout.tsx`);
|
|
131
|
+
if (!generated) throw new Error(`no generated root layout for ${unbounded}`);
|
|
132
|
+
const source = await Bun.file(generated.moduleAbsPath).text();
|
|
133
|
+
expect(source).toContain(boundedLayout);
|
|
134
|
+
await Bun.write(generated.moduleAbsPath, source.replace(boundedLayout, "layout"));
|
|
135
|
+
}
|
|
136
|
+
const { bundlePath } = await new PagesBundleBuilder(app as never, "build", entries).build();
|
|
137
|
+
const ids = await clientReferenceIds(path.dirname(bundlePath));
|
|
138
|
+
ssrManifest.moduleMap = Object.fromEntries(
|
|
139
|
+
ids.map((id) => {
|
|
140
|
+
const file = path.resolve(root, id);
|
|
141
|
+
return [id, { "*": { id: file, chunks: [file, file], name: "*" } }];
|
|
142
|
+
}),
|
|
143
|
+
);
|
|
144
|
+
const shellRead = path.join(root, "shell-read");
|
|
145
|
+
process.env.AKAN_TEST_SHELL_READ = shellRead;
|
|
146
|
+
const rsc = new RscWorker({
|
|
147
|
+
pagesBundlePath: bundlePath,
|
|
148
|
+
pagesBundleBuildId: 1,
|
|
149
|
+
rscRuntimeClientManifest: Object.fromEntries(ids.map((id) => [id, { id, chunks: [], name: "" }])),
|
|
150
|
+
} as never);
|
|
151
|
+
try {
|
|
152
|
+
await rsc.ready;
|
|
153
|
+
await run(async (route) => {
|
|
154
|
+
const request = new Request(`http://localhost/en/${route}`);
|
|
155
|
+
const result = await rsc.renderWithMeta(request);
|
|
156
|
+
if (result.type !== "stream") throw new Error(`expected a rendered page, got ${result.type}`);
|
|
157
|
+
const [rscStream, payloadStream] = result.stream.tee();
|
|
158
|
+
const payload = new Response(payloadStream).arrayBuffer();
|
|
159
|
+
payload.catch(() => undefined);
|
|
160
|
+
const stream = await new SsrFromRscRenderer().render({
|
|
161
|
+
request,
|
|
162
|
+
rscStream,
|
|
163
|
+
ssrManifest,
|
|
164
|
+
lateControl: result.lateControl,
|
|
165
|
+
} as never);
|
|
166
|
+
const html = await readHtml(stream, () => Bun.write(shellRead, ""));
|
|
167
|
+
await rm(shellRead, { force: true });
|
|
168
|
+
return { html, status: result.status ?? 200, payload: new Uint8Array(await payload) };
|
|
169
|
+
});
|
|
170
|
+
} finally {
|
|
171
|
+
rsc.kill();
|
|
172
|
+
delete process.env.AKAN_TEST_SHELL_READ;
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
const bodyOf = async (payload: Uint8Array): Promise<ReactNode> => {
|
|
177
|
+
const html = await createFromNodeStream<ReactElement<{ children: ReactNode }>>(
|
|
178
|
+
Readable.from([payload]),
|
|
179
|
+
ssrManifest as never,
|
|
180
|
+
);
|
|
181
|
+
const body = Children.toArray(html.props.children).find(
|
|
182
|
+
(child): child is ReactElement<{ children: ReactNode }> => isValidElement(child) && child.type === "body",
|
|
183
|
+
);
|
|
184
|
+
return createElement(Fragment, null, body?.props.children);
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
const markupOf = async (node: ReactNode) => {
|
|
188
|
+
const stream = await renderToReadableStream(node, { onError: () => undefined });
|
|
189
|
+
await stream.allReady;
|
|
190
|
+
return await new Response(stream).text();
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
const hydrated = async (
|
|
194
|
+
payload: Uint8Array,
|
|
195
|
+
keptSelectors: string[],
|
|
196
|
+
run: (container: HTMLElement, uncaught: unknown[], recoverable: unknown[]) => void | Promise<void>,
|
|
197
|
+
) => {
|
|
198
|
+
const markup = await markupOf(await bodyOf(payload));
|
|
199
|
+
const { GlobalRegistrator } = await import("@happy-dom/global-registrator");
|
|
200
|
+
GlobalRegistrator.register({ url: "http://localhost/en/" });
|
|
201
|
+
//? getEnv() caches its side, and the SSR render above ran with no window.
|
|
202
|
+
resetEnvCache();
|
|
203
|
+
(globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
|
|
204
|
+
const { hydrateRoot } = await import("react-dom/client");
|
|
205
|
+
const container = document.createElement("div");
|
|
206
|
+
container.innerHTML = markup;
|
|
207
|
+
document.body.appendChild(container);
|
|
208
|
+
const uncaught: unknown[] = [];
|
|
209
|
+
const recoverable: unknown[] = [];
|
|
210
|
+
const kept = keptSelectors.map((selector) => [selector, container.querySelector(selector)] as const);
|
|
211
|
+
//? React's dev check tags a context with the last renderer to provide it, and Fizz rendered these in this process.
|
|
212
|
+
const logged = console.error;
|
|
213
|
+
const quiet = spyOn(console, "error").mockImplementation((...args: unknown[]) => {
|
|
214
|
+
if (!String(args[0]).startsWith("Detected multiple renderers concurrently")) logged(...args);
|
|
215
|
+
});
|
|
216
|
+
let root: ReturnType<typeof hydrateRoot> | undefined;
|
|
217
|
+
try {
|
|
218
|
+
const tree = await bodyOf(payload);
|
|
219
|
+
await act(async () => {
|
|
220
|
+
root = hydrateRoot(container, tree, {
|
|
221
|
+
onUncaughtError: (error) => void uncaught.push(error),
|
|
222
|
+
onCaughtError: () => undefined,
|
|
223
|
+
onRecoverableError: (error) => void recoverable.push(error),
|
|
224
|
+
});
|
|
225
|
+
});
|
|
226
|
+
await act(async () => {});
|
|
227
|
+
for (const [selector, node] of kept) expect(container.querySelector(selector)).toBe(node);
|
|
228
|
+
await run(container, uncaught, recoverable);
|
|
229
|
+
} finally {
|
|
230
|
+
await act(async () => {
|
|
231
|
+
root?.unmount();
|
|
232
|
+
});
|
|
233
|
+
quiet.mockRestore();
|
|
234
|
+
await GlobalRegistrator.unregister();
|
|
235
|
+
resetEnvCache();
|
|
236
|
+
}
|
|
237
|
+
};
|
|
238
|
+
|
|
239
|
+
const withLoggedErrors = async (run: () => Promise<void>) => {
|
|
240
|
+
const logged = spyOn(Logger.prototype, "error").mockImplementation(() => undefined);
|
|
241
|
+
try {
|
|
242
|
+
await run();
|
|
243
|
+
} finally {
|
|
244
|
+
logged.mockRestore();
|
|
245
|
+
}
|
|
246
|
+
};
|
|
247
|
+
|
|
248
|
+
describe("The generated System root layout, built and rendered", () => {
|
|
249
|
+
test("draws a late root failure's notice inside System.Provider, whose bridge started the router its retry calls", async () => {
|
|
250
|
+
const refreshes: string[] = [];
|
|
251
|
+
globalThis.__AKAN_RSC_REFRESH__ = async () => void refreshes.push("refresh");
|
|
252
|
+
try {
|
|
253
|
+
await withLoggedErrors(async () => {
|
|
254
|
+
const routes = { "(late)/_layout.tsx": lateLayoutSource, "(late)/late.tsx": pageSource };
|
|
255
|
+
await withBuiltPages({ routes }, async (render) => {
|
|
256
|
+
const late = await render("late");
|
|
257
|
+
expect(late.status).toBe(200);
|
|
258
|
+
expect(late.html).toContain('<body><!--$?--><template id="B:0"></template><i>root loading</i><!--/$-->');
|
|
259
|
+
expect(late.html).toContain('$RX("B:0"');
|
|
260
|
+
|
|
261
|
+
//? Only the hydrated ClientSsrBridge can start it: the server's own init ran in the worker.
|
|
262
|
+
expect(router.isInitialized).toBe(false);
|
|
263
|
+
await hydrated(late.payload, [], async (container, uncaught) => {
|
|
264
|
+
expect(uncaught).toEqual([]);
|
|
265
|
+
const notice = container.querySelector("#pageContent > [role='alert']");
|
|
266
|
+
expect(notice).not.toBeNull();
|
|
267
|
+
await act(async () => notice?.querySelector("button")?.click());
|
|
268
|
+
expect(refreshes).toEqual(["refresh"]);
|
|
269
|
+
});
|
|
270
|
+
});
|
|
271
|
+
});
|
|
272
|
+
} finally {
|
|
273
|
+
globalThis.__AKAN_RSC_REFRESH__ = undefined;
|
|
274
|
+
}
|
|
275
|
+
}, 30_000);
|
|
276
|
+
|
|
277
|
+
test("keeps the markup and useId values the template had without the boundary, and hydrates them in place", async () => {
|
|
278
|
+
const routes = {
|
|
279
|
+
"(ids)/_layout.tsx": idsLayoutSource,
|
|
280
|
+
"(ids)/ids.tsx": pageSource,
|
|
281
|
+
"(bare)/_layout.tsx": idsLayoutSource,
|
|
282
|
+
"(bare)/bar.tsx": pageSource,
|
|
283
|
+
};
|
|
284
|
+
await withBuiltPages({ routes, unbounded: "(bare)" }, async (render) => {
|
|
285
|
+
const beforeScripts = (html: string) => html.slice(html.indexOf("<body>"), html.indexOf("<script"));
|
|
286
|
+
const bounded = await render("ids");
|
|
287
|
+
const bare = beforeScripts((await render("bar")).html);
|
|
288
|
+
expect(beforeScripts(bounded.html)).toContain('<section id="user"><b id="_R_');
|
|
289
|
+
expect(beforeScripts(bounded.html).replace('data-firstpath="ids"', 'data-firstpath="bar"')).toBe(bare);
|
|
290
|
+
|
|
291
|
+
await hydrated(bounded.payload, ["#pageContent", "#user", "#user b"], (container, uncaught, recoverable) => {
|
|
292
|
+
expect(container.querySelector("#user b")?.id).toStartWith("_R_");
|
|
293
|
+
expect({ uncaught, recoverable }).toEqual({ uncaught: [], recoverable: [] });
|
|
294
|
+
});
|
|
295
|
+
});
|
|
296
|
+
}, 30_000);
|
|
297
|
+
});
|
package/biome.base.json
CHANGED
|
@@ -227,7 +227,8 @@
|
|
|
227
227
|
],
|
|
228
228
|
"plugins": [
|
|
229
229
|
"./node_modules/@akanjs/devkit/lint/no-document-cookie.grit",
|
|
230
|
-
"./node_modules/@akanjs/devkit/lint/no-web-storage.grit"
|
|
230
|
+
"./node_modules/@akanjs/devkit/lint/no-web-storage.grit",
|
|
231
|
+
"./node_modules/@akanjs/devkit/lint/no-import-common-err.grit"
|
|
231
232
|
]
|
|
232
233
|
},
|
|
233
234
|
{
|
package/cloud/cloudApi.test.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { readFile, rm } from "node:fs/promises";
|
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import dayjs from "dayjs";
|
|
5
5
|
import type { Workspace } from "../commandDecorators";
|
|
6
|
-
import { tempDirs, writeJson, writeText } from "../testHelpers";
|
|
6
|
+
import { tempDirs, writeJson, writeText } from "../test/testHelpers";
|
|
7
7
|
import { CloudApi } from "./cloudApi";
|
|
8
8
|
|
|
9
9
|
// The cloud rotates a refresh token on every use and treats a second use as theft, revoking every session.
|
package/cloud/configLock.test.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { describe, expect, test } from "bun:test";
|
|
2
2
|
import { readFile, writeFile } from "node:fs/promises";
|
|
3
3
|
import path from "node:path";
|
|
4
|
-
import { tempDirs } from "../testHelpers";
|
|
4
|
+
import { tempDirs } from "../test/testHelpers";
|
|
5
5
|
import { ConfigLock } from "./configLock";
|
|
6
6
|
|
|
7
7
|
const makeRoot = tempDirs("akan-config-lock-");
|
|
@@ -2,7 +2,7 @@ import { describe, expect, test } from "bun:test";
|
|
|
2
2
|
import { mkdir, stat } from "node:fs/promises";
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import dayjs from "dayjs";
|
|
5
|
-
import { tempDirs } from "../testHelpers";
|
|
5
|
+
import { tempDirs } from "../test/testHelpers";
|
|
6
6
|
import { GlobalConfig } from "./globalConfig";
|
|
7
7
|
|
|
8
8
|
const tempHome = tempDirs("akan-global-config-");
|
package/cloud/globalConfig.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { rm, writeFile } from "node:fs/promises";
|
|
2
2
|
import { trimTrailingSlashes } from "akanjs/common";
|
|
3
3
|
import dayjs from "dayjs";
|
|
4
|
-
import { FileSys } from "../fileSys";
|
|
4
|
+
import { FileSys } from "../util/fileSys";
|
|
5
5
|
import { ConfigLock } from "./configLock";
|
|
6
6
|
import {
|
|
7
7
|
type AccessToken,
|
|
@@ -3,7 +3,7 @@ import { createHash } from "node:crypto";
|
|
|
3
3
|
import { truncate, writeFile } from "node:fs/promises";
|
|
4
4
|
import path from "node:path";
|
|
5
5
|
import type { Workspace } from "../commandDecorators";
|
|
6
|
-
import { tempDirs } from "../testHelpers";
|
|
6
|
+
import { tempDirs } from "../test/testHelpers";
|
|
7
7
|
import { CloudApi } from "./cloudApi";
|
|
8
8
|
import { UpdatePackUpload } from "./updatePackUpload";
|
|
9
9
|
|
|
@@ -12,6 +12,11 @@ import type { CodeAgentProxy } from "./CodeAgentProxy";
|
|
|
12
12
|
import { CodeSessionIndex } from "./CodeSessionIndex";
|
|
13
13
|
import { WorkspaceTrust } from "./WorkspaceTrust";
|
|
14
14
|
|
|
15
|
+
type PrepareRequest = (
|
|
16
|
+
model: unknown,
|
|
17
|
+
options?: Record<string, unknown>,
|
|
18
|
+
) => Promise<{ model: { compat?: Record<string, unknown> } }>;
|
|
19
|
+
|
|
15
20
|
export interface AkanCodeServicesOptions {
|
|
16
21
|
workspaceRoot: string;
|
|
17
22
|
cwd: string;
|
|
@@ -30,6 +35,8 @@ export class AkanCodeServices {
|
|
|
30
35
|
enableAnalytics: false,
|
|
31
36
|
quietStartup: true,
|
|
32
37
|
compaction: { reserveTokens: AkanCodeCompaction.reserveFloor },
|
|
38
|
+
// pi 1.5 defaults to "idle", which sends billed cache refreshes for up to 30 minutes between turns.
|
|
39
|
+
cacheWarming: "streaming",
|
|
33
40
|
});
|
|
34
41
|
}
|
|
35
42
|
|
|
@@ -43,11 +50,27 @@ export class AkanCodeServices {
|
|
|
43
50
|
: akanCodePaths.authFile(),
|
|
44
51
|
modelsPath: akanCodePaths.modelsFile(),
|
|
45
52
|
});
|
|
53
|
+
AkanCodeServices.#holdMessageThreadsOff(runtime);
|
|
46
54
|
if (proxy) await proxy.apply(runtime);
|
|
47
55
|
else await AkanEnvKeys.apply(runtime, workspaceRoot);
|
|
48
56
|
return runtime;
|
|
49
57
|
}
|
|
50
58
|
|
|
59
|
+
// pi 1.5 turned Anthropic message threads on for api.anthropic.com; a models.json `compat` that names it still wins.
|
|
60
|
+
static #holdMessageThreadsOff(runtime: ModelRuntime) {
|
|
61
|
+
const target = runtime as unknown as { prepareRequest?: PrepareRequest };
|
|
62
|
+
const original = target.prepareRequest?.bind(runtime);
|
|
63
|
+
if (!original) throw new Error("The model runtime no longer exposes prepareRequest; update AkanCodeServices");
|
|
64
|
+
target.prepareRequest = async (model, options) => {
|
|
65
|
+
const prepared = await original(model, options);
|
|
66
|
+
if (prepared.model.compat?.supportsMessageThreads !== undefined) return prepared;
|
|
67
|
+
return {
|
|
68
|
+
...prepared,
|
|
69
|
+
model: { ...prepared.model, compat: { ...prepared.model.compat, supportsMessageThreads: false } },
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
|
|
51
74
|
static sessions(workspaceRoot: string, cwd: string, profile: CodeAgentProfile, resume?: string) {
|
|
52
75
|
//* `remote` has no store of its own yet, so it keeps a file session: a pod worker's suspended asks need it.
|
|
53
76
|
if (profile.session.store === "memory") return SessionManager.inMemory(cwd);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { existsSync } from "node:fs";
|
|
2
2
|
import { homedir } from "node:os";
|
|
3
3
|
import path from "node:path";
|
|
4
|
-
import { FileSys } from "../../fileSys";
|
|
4
|
+
import { FileSys } from "../../util/fileSys";
|
|
5
5
|
import { AkanCodeEnv } from "./AkanCodeEnv";
|
|
6
6
|
|
|
7
7
|
// Two candidates: the CLI bundle flattens entry chunks into the package root, where `skills/` is a sibling.
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, test } from "bun:test";
|
|
2
|
+
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { tmpdir } from "node:os";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import type { ModelRuntime } from "@earendil-works/pi-coding-agent";
|
|
6
|
+
import { AkanCodeServices } from "./AkanCodeServices";
|
|
7
|
+
import { akanCodePaths } from "./akanCodePaths";
|
|
8
|
+
|
|
9
|
+
const saved: Record<string, string | undefined> = {};
|
|
10
|
+
let home = "";
|
|
11
|
+
|
|
12
|
+
beforeEach(() => {
|
|
13
|
+
home = mkdtempSync(path.join(tmpdir(), "akan-code-services-test-"));
|
|
14
|
+
for (const key of ["AKAN_CODE_HOME", "ANTHROPIC_API_KEY"]) saved[key] = process.env[key];
|
|
15
|
+
process.env.AKAN_CODE_HOME = home;
|
|
16
|
+
process.env.ANTHROPIC_API_KEY = "test-key-never-sent";
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
afterEach(() => {
|
|
20
|
+
rmSync(home, { recursive: true, force: true });
|
|
21
|
+
for (const [key, value] of Object.entries(saved)) {
|
|
22
|
+
if (value === undefined) delete process.env[key];
|
|
23
|
+
else process.env[key] = value;
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
const threadsOf = async (runtime: ModelRuntime) => {
|
|
28
|
+
const model = runtime.getModels("anthropic")[0];
|
|
29
|
+
if (!model) throw new Error("pi lists no anthropic model");
|
|
30
|
+
expect(model.baseUrl).toContain("api.anthropic.com");
|
|
31
|
+
const prepare = (runtime as unknown as { prepareRequest: (model: unknown, options: object) => Promise<unknown> })
|
|
32
|
+
.prepareRequest;
|
|
33
|
+
const prepared = (await prepare.call(runtime, model, {})) as { model: { compat?: Record<string, unknown> } };
|
|
34
|
+
return prepared.model.compat?.supportsMessageThreads;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
describe("AkanCodeServices holds the defaults akan code had on pi 1.3.0", () => {
|
|
38
|
+
test("prompt caches are warmed only while a turn streams, never in the idle time between turns", () => {
|
|
39
|
+
expect(AkanCodeServices.settings().getCacheWarmingMode()).toBe("streaming");
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
test("an Anthropic request carries the whole conversation instead of continuing a server-side thread", async () => {
|
|
43
|
+
expect(await threadsOf(await AkanCodeServices.runtime(home))).toBe(false);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
test("models.json can still turn Anthropic message threads on", async () => {
|
|
47
|
+
mkdirSync(path.dirname(akanCodePaths.modelsFile()), { recursive: true });
|
|
48
|
+
writeFileSync(
|
|
49
|
+
akanCodePaths.modelsFile(),
|
|
50
|
+
JSON.stringify({ providers: { anthropic: { compat: { supportsMessageThreads: true } } } }),
|
|
51
|
+
);
|
|
52
|
+
expect(await threadsOf(await AkanCodeServices.runtime(home))).toBe(true);
|
|
53
|
+
});
|
|
54
|
+
});
|
|
@@ -41,7 +41,7 @@ export const akanSystemPrompt = (profile: CodeAgentProfile) => {
|
|
|
41
41
|
"## How to answer",
|
|
42
42
|
"",
|
|
43
43
|
"- Answer in as few words as carry the answer. A short question gets one sentence with no heading.",
|
|
44
|
-
"- Do not open with what you are about to do, and do not
|
|
44
|
+
"- Do not open with what you are about to do, and do not retell the tool calls at the end; they are already on the user's screen. A turn that changed files closes with those files and what `akan_verify` said.",
|
|
45
45
|
"- Skip headings, bold labels and bullet lists unless the answer is genuinely a list. Prose is shorter.",
|
|
46
46
|
"- State a file as `path:line`. Do not paste a file back that the user can open.",
|
|
47
47
|
"- Say what you could not do, and why, in one line. Do not offer alternatives nobody asked for.",
|
|
@@ -4,7 +4,7 @@ import path from "node:path";
|
|
|
4
4
|
import type { ExtensionAPI, InlineExtension } from "@earendil-works/pi-coding-agent";
|
|
5
5
|
import { type CodeAgentEvent, type CodeAgentProfile, codeAgentPresets } from "akanjs/common";
|
|
6
6
|
import { WorkspaceExecutor } from "../../executors";
|
|
7
|
-
import { isolateEnv, tempDirs } from "../../testHelpers";
|
|
7
|
+
import { isolateEnv, tempDirs } from "../../test/testHelpers";
|
|
8
8
|
import { AkanCodePlugins } from "../tools/AkanCodePlugins";
|
|
9
9
|
import { akanCodeDefaultModel, type CodeAgentModelRef } from "./akanCodeModel";
|
|
10
10
|
import { akanCodePaths } from "./akanCodePaths";
|