From 87d63f487d4d7288dc9383db3ab31b72db25f0a9 Mon Sep 17 00:00:00 2001 From: itam-automation <203017558+itam-automation@users.noreply.github.com> Date: Wed, 11 Nov 2026 12:48:00 +0100 Subject: [PATCH 1/2] Add ATF regression test for IRE identification of computers --- .../README.md | 36 ++++++++++ .../atf_ire_identification.js | 70 +++++++++++++++++++ 2 files changed, 106 insertions(+) create mode 100644 Specialized Areas/ATF Steps/IRE Identification Regression Test/README.md create mode 100644 Specialized Areas/ATF Steps/IRE Identification Regression Test/atf_ire_identification.js diff --git a/Specialized Areas/ATF Steps/IRE Identification Regression Test/README.md b/Specialized Areas/ATF Steps/IRE Identification Regression Test/README.md new file mode 100644 index 0000000000..707944afd9 --- /dev/null +++ b/Specialized Areas/ATF Steps/IRE Identification Regression Test/README.md @@ -0,0 +1,36 @@ +# IRE Identification Regression Test + +An ATF "Run Server Side Script" step that checks how the Identification and Reconciliation Engine (IRE) identifies computers. It catches changes that would let imports create duplicate CIs, for example after an upgrade or after someone edits the identification rules. + +## What it checks + +1. The same computer sent twice gives `INSERT`, then `UPDATE` or `NO_CHANGE` with the same sys_id, and only one CI exists. +2. A computer sent again under a new name is found by its serial number. +3. A computer with a different serial number becomes a new CI. +4. A computer without name, serial number or MAC address is rejected with `MISSING_MATCHING_ATTRIBUTES` instead of being inserted. + +The step calls `sn_cmdb.IdentificationEngine.createOrUpdateCI()`, which is what integrations and import scripts use. ATF rolls back the CIs the test creates. + +## Setup + +1. Automated Test Framework > Tests > New. Give the test a name, for example "IRE identification: computers". +2. Add Test Step > Server > Run Server Side Script. +3. Paste the content of `atf_ire_identification.js` and save. +4. Run the test. + +## Adjusting it + +- `DATA_SOURCE` must be a choice value of `cmdb_ci.discovery_source`. Use the source your imports use, so the test runs through the same reconciliation rules. +- `CLASS_NAME` is `cmdb_ci_computer`. For servers or network gear, change the class and the attributes to what your identification rule for that class uses. +- The expectations describe the out-of-box hardware rule (serial number, then other attributes). If you changed the rules on purpose, change the expectations as well. The test then documents how identification is supposed to work on your instance. + +## Tested + +On a personal developer instance (release Brazil). As an ATF step, all IRE expectations passed and ATF rolled back the CIs it created. The two count checks failed in that run only because the test had been created while a scoped application was selected (see below). The same checks run in the global scope as a background script all passed: INSERT then NO_CHANGE for the same computer, UPDATE with the same sys_id after a rename, a new CI for a new serial number, and `MISSING_MATCHING_ATTRIBUTES` without identifying attributes. + +## Requirements + +- The ATF step runs as the user who runs the test, who needs to be allowed to write CIs. +- Create the test in the global scope. A test that is created while a scoped application is selected runs in that scope, and with runtime access enforcement the read on `cmdb_ci_computer` is denied ("must declare a cross scope access privilege"), so the count checks fail. +- Server-side scripts in ATF use Jasmine 3.1, `jasmine.getEnv().execute()` at the end starts the specs. +- ES5 only, no ES2021 features. diff --git a/Specialized Areas/ATF Steps/IRE Identification Regression Test/atf_ire_identification.js b/Specialized Areas/ATF Steps/IRE Identification Regression Test/atf_ire_identification.js new file mode 100644 index 0000000000..e1f5024e80 --- /dev/null +++ b/Specialized Areas/ATF Steps/IRE Identification Regression Test/atf_ire_identification.js @@ -0,0 +1,70 @@ +/** + * ATF step "Run Server Side Script" (Jasmine 3.1). + * + * Checks that the identification rules for computers still behave as expected: + * the same device sent twice, or sent again under a new name, must not become a second CI. + * Run it after upgrades and after changes to identification rules. + * + * ATF rolls back the CIs created during the test. + */ +(function (outputs, steps, params, stepResult, assertEqual) { + + // must be a choice value of cmdb_ci.discovery_source + var DATA_SOURCE = 'ServiceNow'; + var CLASS_NAME = 'cmdb_ci_computer'; + + function sendToIre(values) { + var payload = { items: [{ className: CLASS_NAME, values: values }] }; + var output = JSON.parse(sn_cmdb.IdentificationEngine.createOrUpdateCI(DATA_SOURCE, JSON.stringify(payload))); + return output.items[0]; + } + + function countBySerial(serial) { + var ga = new GlideAggregate(CLASS_NAME); + ga.addQuery('serial_number', serial); + ga.addAggregate('COUNT'); + ga.query(); + return ga.next() ? parseInt(ga.getAggregate('COUNT'), 10) : 0; + } + + describe('IRE identification for ' + CLASS_NAME, function () { + + it('creates one CI when the same computer is sent twice', function () { + var first = sendToIre({ name: 'ATF-IRE-NB-01', serial_number: 'ATFIRE0001' }); + var second = sendToIre({ name: 'ATF-IRE-NB-01', serial_number: 'ATFIRE0001' }); + + expect(first.operation).toBe('INSERT'); + expect(['UPDATE', 'NO_CHANGE']).toContain(second.operation); + expect(second.sysId).toBe(first.sysId); + expect(countBySerial('ATFIRE0001')).toBe(1); + }); + + it('finds the computer by serial number after it was renamed', function () { + var first = sendToIre({ name: 'ATF-IRE-NB-02', serial_number: 'ATFIRE0002' }); + var renamed = sendToIre({ name: 'ATF-IRE-NB-02-NEW', serial_number: 'ATFIRE0002' }); + + expect(renamed.sysId).toBe(first.sysId); + expect(countBySerial('ATFIRE0002')).toBe(1); + }); + + it('creates a second CI for a different serial number', function () { + var first = sendToIre({ name: 'ATF-IRE-NB-03', serial_number: 'ATFIRE0003' }); + var other = sendToIre({ name: 'ATF-IRE-NB-04', serial_number: 'ATFIRE0004' }); + + expect(other.operation).toBe('INSERT'); + expect(other.sysId).not.toBe(first.sysId); + }); + + it('rejects a computer without any identifying attribute', function () { + var result = sendToIre({ asset_tag: 'ATF-IRE-TAG-05', short_description: 'no name, serial or MAC address' }); + var codes = (result.errors || []).map(function (e) { + return e.error; + }); + + expect(codes).toContain('MISSING_MATCHING_ATTRIBUTES'); + }); + }); + +})(outputs, steps, params, stepResult, assertEqual); + +jasmine.getEnv().execute(); From f38324c4ec4f7cd8f9ea688ac0610fe511b50f6e Mon Sep 17 00:00:00 2001 From: itam-automation <203017558+itam-automation@users.noreply.github.com> Date: Wed, 11 Nov 2026 16:32:34 +0100 Subject: [PATCH 2/2] README: result of a full ATF run in the global scope --- .../ATF Steps/IRE Identification Regression Test/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Specialized Areas/ATF Steps/IRE Identification Regression Test/README.md b/Specialized Areas/ATF Steps/IRE Identification Regression Test/README.md index 707944afd9..323cc60ff3 100644 --- a/Specialized Areas/ATF Steps/IRE Identification Regression Test/README.md +++ b/Specialized Areas/ATF Steps/IRE Identification Regression Test/README.md @@ -26,7 +26,7 @@ The step calls `sn_cmdb.IdentificationEngine.createOrUpdateCI()`, which is what ## Tested -On a personal developer instance (release Brazil). As an ATF step, all IRE expectations passed and ATF rolled back the CIs it created. The two count checks failed in that run only because the test had been created while a scoped application was selected (see below). The same checks run in the global scope as a background script all passed: INSERT then NO_CHANGE for the same computer, UPDATE with the same sys_id after a rename, a new CI for a new serial number, and `MISSING_MATCHING_ATTRIBUTES` without identifying attributes. +On a personal developer instance (release Brazil), with the test created in the global scope: all four specs passed, and ATF rolled back the CIs the test created. A first run of a test that had been created while a scoped application was selected failed the two count checks (see Requirements). ## Requirements