From 8cbd7da1de5396bcb9d80a97555a5ed4423f180b Mon Sep 17 00:00:00 2001 From: Steve Ramage Date: Sun, 12 Apr 2026 09:54:08 -0700 Subject: [PATCH] fix: fix support for MemoryPressureWatch= after update --- .../semanticdata/optionvalues/AiGenerated.kt | 2 +- ...nfigParseMemoryPressureWatchOptionValue.kt | 6 +-- .../SemanticDataRepositoryTest.kt | 48 +++++++++++++++++++ 3 files changed, 52 insertions(+), 4 deletions(-) diff --git a/src/main/kotlin/net/sjrx/intellij/plugins/systemdunitfiles/semanticdata/optionvalues/AiGenerated.kt b/src/main/kotlin/net/sjrx/intellij/plugins/systemdunitfiles/semanticdata/optionvalues/AiGenerated.kt index b9cf1a5d..0d171108 100644 --- a/src/main/kotlin/net/sjrx/intellij/plugins/systemdunitfiles/semanticdata/optionvalues/AiGenerated.kt +++ b/src/main/kotlin/net/sjrx/intellij/plugins/systemdunitfiles/semanticdata/optionvalues/AiGenerated.kt @@ -123,7 +123,7 @@ fun getAllAIGeneratedValidators(): Map { Validator("config_parse_macvlan_broadcast_queue_threshold", "0") to ConfigParseMacvlanBroadcastQueueThresholdOptionValue() as OptionValueInformation, Validator("config_parse_macvlan_mode", "0") to ConfigParseMacvlanModeOptionValue() as OptionValueInformation, Validator("config_parse_mdi", "0") to ConfigParseMdiOptionValue() as OptionValueInformation, - Validator("config_parse_memory_pressure_watch", "0") to ConfigParseMemoryPressureWatchOptionValue() as OptionValueInformation, + Validator("config_parse_pressure_watch", "0") to ConfigParseMemoryPressureWatchOptionValue() as OptionValueInformation, Validator("config_parse_mtu", "AF_INET6") to ConfigParseMtuOptionValue() as OptionValueInformation, Validator("config_parse_multicast_router", "0") to ConfigParseMulticastRouterOptionValue() as OptionValueInformation, Validator("config_parse_ndisc_start_dhcp6_client", "0") to ConfigParseNdiscStartDhcp6ClientOptionValue() as OptionValueInformation, diff --git a/src/main/kotlin/net/sjrx/intellij/plugins/systemdunitfiles/semanticdata/optionvalues/ai/ConfigParseMemoryPressureWatchOptionValue.kt b/src/main/kotlin/net/sjrx/intellij/plugins/systemdunitfiles/semanticdata/optionvalues/ai/ConfigParseMemoryPressureWatchOptionValue.kt index 24ccb4e3..13cfdccd 100644 --- a/src/main/kotlin/net/sjrx/intellij/plugins/systemdunitfiles/semanticdata/optionvalues/ai/ConfigParseMemoryPressureWatchOptionValue.kt +++ b/src/main/kotlin/net/sjrx/intellij/plugins/systemdunitfiles/semanticdata/optionvalues/ai/ConfigParseMemoryPressureWatchOptionValue.kt @@ -6,13 +6,13 @@ import net.sjrx.intellij.plugins.systemdunitfiles.semanticdata.optionvalues.Simp /** * Validator for Swap.MemoryPressureWatch - * C Function: config_parse_memory_pressure_watch(0) + * C Function: config_parse_pressure_watch(0) * Used by Options: Swap.MemoryPressureWatch - * + * * Accepts boolean values (yes/no/1/0/true/false/on/off/y/n/t/f) or special values (auto/skip). */ class ConfigParseMemoryPressureWatchOptionValue : SimpleGrammarOptionValues( - "config_parse_memory_pressure_watch", + "config_parse_pressure_watch", SequenceCombinator( FlexibleLiteralChoiceTerminal("yes", "no", "1", "0", "true", "false", "on", "off", "y", "n", "t", "f", "auto", "skip"), EOF() diff --git a/src/test/kotlin/net/sjrx/intellij/plugins/systemdunitfiles/semanticdata/SemanticDataRepositoryTest.kt b/src/test/kotlin/net/sjrx/intellij/plugins/systemdunitfiles/semanticdata/SemanticDataRepositoryTest.kt index 6fa74585..4ae8fe03 100644 --- a/src/test/kotlin/net/sjrx/intellij/plugins/systemdunitfiles/semanticdata/SemanticDataRepositoryTest.kt +++ b/src/test/kotlin/net/sjrx/intellij/plugins/systemdunitfiles/semanticdata/SemanticDataRepositoryTest.kt @@ -4,6 +4,54 @@ import net.sjrx.intellij.plugins.systemdunitfiles.AbstractUnitFileTest import net.sjrx.intellij.plugins.systemdunitfiles.semanticdata.optionvalues.* class SemanticDataRepositoryTest : AbstractUnitFileTest() { + + /** + * Verifies that every registered validator references a function name that actually + * exists in one of the gperf files. Catches stale validators after upstream renames. + * + * Validators kept for backward compatibility with older systemd versions should be + * added to the allowlist below with a comment explaining why. + */ + fun testAllRegisteredValidatorsExistInGperfFiles() { + val sdr = SemanticDataRepository.instance + + // Validators intentionally kept for backward compatibility with older systemd versions + val legacyAllowlist = setOf( + // Renamed to config_parse_unit_cpu_set in systemd; old name kept for older versions + Validator("config_parse_allowed_cpuset", "0"), + // Deprecated cgroup v1 options removed from gperf but still valid on older systemd + Validator("config_parse_cpu_shares", "0"), + Validator("config_parse_blockio_weight", "0"), + Validator("config_parse_blockio_bandwidth", "0"), + ) + + // Collect all Validator instances referenced in the gperf files + val gperfValidators = mutableSetOf() + for (fileClass in FileClass.entries) { + for (section in sdr.getSectionNamesForSectionAndKey(fileClass)) { + for (key in sdr.getAllowedKeywordsInSectionFromValidators(fileClass, section)) { + gperfValidators.add(sdr.getValidatorForSectionAndKey(fileClass, section, key)) + } + } + } + + // Check all registered validators (not just AI-generated ones) + val registeredValidators = sdr.getValidatorMap() + val staleValidators = registeredValidators.keys.filter { validator -> + // Skip the NullOptionValue sentinel and wildcard validators — these are synthetic + // and intentionally don't correspond to gperf entries + validator.validatorName != "NULL" + && validator.validatorArgument != "*" + && validator !in gperfValidators + && validator !in legacyAllowlist + } + + assertTrue( + "Registered validators reference function names not found in any gperf file: " + + staleValidators.joinToString(", "), + staleValidators.isEmpty() + ) + } fun testInteresting() { val sdr = SemanticDataRepository.instance assertInstanceOf(sdr.getOptionValidator(FileClass.UNIT_FILE,"Socket", "SendSIGKILL"), BooleanOptionValue::class.java)