fix(build-gate): resolve commands by toolchain (#40)

This commit is contained in:
kami
2026-07-21 02:18:04 +04:00
parent 119f59d637
commit 6e844ef1e1
15 changed files with 157 additions and 6 deletions
@@ -18,6 +18,12 @@ package com.correx.core.artifacts.kind
*/
object KindContractTable {
/** Toolchain selected by the build gate for a produced source or manifest kind. */
enum class Toolchain(val profileKey: String) {
NODE("node"),
JVM("jvm"),
}
/** A single assertion template — a kind's requirement before it is bound to a concrete path. */
private data class Template(
val id: String,
@@ -133,6 +139,9 @@ object KindContractTable {
private val CHECKED_IN: Map<String, List<Template>> = TS_REACT + KOTLIN + GENERIC
private val TOOLCHAINS = TS_REACT.keys.associateWith { Toolchain.NODE } +
KOTLIN.keys.associateWith { Toolchain.JVM }
/** Project-supplied additive overrides, keyed by kind id. Set at wiring time; empty by default. */
@Volatile
var projectOverrides: Map<String, List<ContractAssertion>> = emptyMap()
@@ -157,5 +166,8 @@ object KindContractTable {
return (base + overrides).filterNot { it.id == "file_nonempty" && isDotfile(path) }
}
/** The build toolchain implied by a checked-in kind, or null for stack-neutral kinds. */
fun toolchainFor(kindId: String): Toolchain? = TOOLCHAINS[kindId]
private fun isDotfile(path: String): Boolean = path.substringAfterLast('/').startsWith(".")
}
@@ -101,4 +101,13 @@ class KindContractTableTest {
assertTrue("contains" in ids, "override assertion must be appended")
assertTrue("file_nonempty" in ids, "checked-in assertions remain")
}
@Test
fun `toolchain follows checked in source and manifest kinds`() {
assertEquals(KindContractTable.Toolchain.NODE, KindContractTable.toolchainFor("react_entry"))
assertEquals(KindContractTable.Toolchain.NODE, KindContractTable.toolchainFor("package_json"))
assertEquals(KindContractTable.Toolchain.JVM, KindContractTable.toolchainFor("kotlin_service"))
assertEquals(KindContractTable.Toolchain.JVM, KindContractTable.toolchainFor("gradle_module"))
assertEquals(null, KindContractTable.toolchainFor("docs"))
}
}