Skip to content

TEST: Check the hardware lookup examples when the cloud fails or finds nothing - #235

Merged
jwrosewell merged 2 commits into
rcfrom
test/hardware-lookup-follow-up
Nov 23, 2026
Merged

jwrosewell merged 2 commits into
rcfrom
test/hardware-lookup-follow-up

Conversation

@jwrosewell

Copy link
Copy Markdown
Contributor

Follows #234, which made the cloud TAC lookup example (TacCloud.java) and the cloud native model lookup example (NativeModelCloud.java) say in one line when the resource key does not include HardwarePlatform.Profiles, and made their live tests fail rather than pass when no device is listed.

Problem

Reviews of #234 found three gaps.

  1. A property list that could not be fetched at first. The examples decide from the hardware engine's properties, which come from the cloud's accessible properties for the key. When that request failed as the pipeline was built, with a 5xx answer, a timeout or no connection, nothing was known to be missing, so the examples ran the lookups. Processing fetches the list again before the first lookup. If that worked for a key without the hardware lookup, the examples printed each heading with No devices are associated with this TAC. under it and exited with code 0. That is a decision made from an empty lookup rather than from the list.
  2. No test of a lookup that matches nothing. The line the examples print when a lookup matches no device was never checked.
  3. The stand-in test did not check for logged errors. HardwareLookupWithoutProfilesTest checked the exit code and the line, but would still pass if an error or a stack trace were logged on the way.

AGENTS.md also said the examples "end with that error" against the published 4.5.130 packages without naming the error. Two old comments were wrong too. TacCloud pointed at a "NativeModelLookup" example, which is NativeModelCloud, and NativeModelCloud spelled pipeline wrongly.

What changed

The examples, in the first commit:

  • Each example still checks the hardware engine's properties before any lookup, so with a list fetched as the pipeline was built, a key without the lookup gets the one line and no lookup is made, as before.
  • After processing a lookup, each example checks the properties again before it uses the result. Processing fetches the accessible properties first when they are not known, and throws the cloud service's error if that fails again. So the decision is always made from a loaded list. A key without the lookup gets the one line and exit code 0, and a second failure ends with the cloud service's error and a non-zero exit code.
  • Processing a lookup is the only way the cloud request engine can be asked for the list again through methods that exist in both the published 4.5.130 packages and the packages on rc, which the examples have to compile against. So when the first request failed and the second gives a key without the lookup, the first lookup request is made before the decision, and its result is not used.
  • The one line is written by one method in each example, writeNoHardwareLookup, and the two comments are corrected.

The tests, in the second commit, rename HardwareLookupWithoutProfilesTest to HardwareLookupStandInTest. Its stand-in for the cloud service on 127.0.0.1 answers the accessible properties, the evidence keys and the lookup with what each test sets, and anything else with 404. Each case runs for both examples, with a stand-in key and _51DEGREES_CLOUD_ENDPOINT pointing at the stand-in.

Case Stand-in answers Required
Without profiles accessible properties with no hardware element exit code 0, the whole line compared word for word with both tagged links, the "Find out more" section after it, no lookup heading, no lookup request, nothing logged as an error and no stack trace
No devices accessible properties with the hardware element, and each lookup with {"hardware":{"profiles":[]}} exit code 0, each heading followed by \tNo devices are associated with this TAC. or \tNo devices are associated with this native model name., no line saying the key lacks the lookup, one lookup request per value, nothing logged as an error and no stack trace
Properties fail every time accessible properties with 500 and an error message, every time a non-zero exit code, the cloud service's message after a line logged as an error, no line saying the key lacks the lookup, no heading and no lookup request
Properties fail once accessible properties with 500 once, then with no hardware element, and the lookup with an answer that has no hardware element exit code 0, the whole line, no heading, two requests for the accessible properties, at most one lookup request and nothing logged as an error. The library logs the first failure as a warning with its stack trace, so a stack trace is allowed in this case only

The log lines carry colour codes around their level, so the test removes them before it looks for a line logged as an error. The two new fixtures, accessibleproperties-with-hardware.json and json-no-devices.json, come from answers the staging cloud gave, with the accessible properties cut down to what the examples use. Neither holds a key.

AGENTS.md now says what the examples print when a lookup matches nothing and when the property list cannot be fetched. It also names what happens against the published 4.5.130 packages with a key without the lookup. The examples log Aspect properties could not be loaded for fiftyone.devicedetection.cloud.flowelements.HardwareProfileCloudEngine, end with java.lang.RuntimeException: Failed to load aspect properties for element 'hardware' and exit with code 1.

The live tests, TacCloudTest and NativeModelCloudTest, are unchanged. They are skipped when KeyHelper finds no usable key in _51DEGREES_RESOURCE_KEY_BESPOKE, which means the variable is not set or its value is not shaped like a resource key, as the other live tests in this repository are.

How this was verified

Run in examples/device-detection with JDK 21, offline, with the dev profile and the libraries of rc installed from the root with mvnw install -Pdev -DskipTests -pl device-detection/device-detection.cloud,device-detection/device-detection -am. The library sources are unchanged since #234.

What Command Result
Related tests, no key and no network mvnw -o -Pdev -pl console -am clean test -Dtest=HardwareLookupStandInTest,HardwareLookupOutputTest,CloudExamplesWithoutKeyTest,FindOutMoreCoverageTest,ConsoleConfigurationCoverageTest,CloudDropInTest#cloudResultsReadAsOnPremise,KeyHelperTest,FindOutMoreTest,ExampleProcessTest,PropertyHelperTest -DfailIfNoTests=false, with every variable holding a key removed shared module 22 run, 0 failed. Console 21 run, 0 failed, including the 8 stand-in tests
The new stand-in tests against the examples as merged in #234 same, -Dtest=HardwareLookupStandInTest 8 run, 2 failed, being tacCloudPropertiesFailOnce and nativeModelCloudPropertiesFailOnce, because those examples printed the headings with no devices instead of the line
Live tests, a key that carries the lookup, against the staging cloud mvnw -o -Pdev -pl console -am clean test -Dtest=TacCloudTest,NativeModelCloudTest, with that key in _51DEGREES_RESOURCE_KEY_BESPOKE and _51DEGREES_CLOUD_ENDPOINT naming the staging cloud 2 run, 0 failed. The same devices as in #234, such as Apple iPhone 6 (A1586) and Samsung Galaxy S10 (SC-03L)
Live tests, the key behind _51DEGREES_RESOURCE_KEY_BESPOKE, production same, with that key 2 run, 2 failed with The resource key in _51DEGREES_RESOURCE_KEY_BESPOKE does not include HardwarePlatform.Profiles, which the TAC lookup needs. and ... which the native model lookup needs.
Compile against the published 4.5.130 packages, as the fresh clone workflow does mvnw -o -pl console -am clean test-compile BUILD SUCCESS
Environment variable names pwsh ci/check-environment-variable-names.ps1 clean
Campaign tags common-ci scripts/utm-lint.ps1 -RepoRoot . -Campaign 51degrees-java clean
Locale pwsh ci/check-root-locale.ps1 clean

What remains

  • The live tests will fail in CI until the key behind the _51DEGREES_RESOURCE_KEY_BESPOKE secret is replaced with one that carries every CloudV5Bespoke property. The current key does not include HardwarePlatform.Profiles, so TacCloudTest and NativeModelCloudTest fail. That failure is intended, and it is already the case on rc since TEST: Check the cloud hardware lookup examples return devices #234.
  • The stand-in tests pass only with the dev profile, which CI uses, or with the packages a publish has just built. The published 4.5.130 packages read the endpoint from another variable and cannot build the pipeline for a key without the hardware element, which Build a cloud engine whose product the resource key lacks, and log that once #84 and Give every environment variable one _51DEGREES_ name #105 changed on rc after 4.5.130.
  • Not changed here. The cloud request engine logs a NullPointerException rather than the status when the cloud answers a request with an error status and no body. The stand-in gives every error a body, as the cloud service does.

The same behavior is being brought to the TAC and native model lookup examples and tests in the .NET, Python, Node.js, PHP and Rust repositories, so all six languages print and test these lookups in the same way.

… TAC and native model examples

When the cloud's accessible properties request failed as the pipeline was
built, the examples ran the lookups. If processing then fetched the list
for a key without the hardware lookup, they printed each heading with "No
devices are associated" under it and exited with code 0, deciding from an
empty lookup rather than from the list.

Each example still checks the hardware engine's properties before any
lookup. After processing a lookup, which fetches the accessible
properties first when they are not known and throws the cloud service's
error if that fails again, it checks them once more before using the
result. So the decision is always made from a loaded list, a key without
the lookup gets the one line and exit code 0, and a second failure ends
with the cloud service's error and a non-zero exit code. The line is
written by one method in each example.

Two comments are corrected. TacCloud named a NativeModelLookup example,
which is NativeModelCloud, and NativeModelCloud spelled pipeline wrongly.
…s nothing

HardwareLookupWithoutProfilesTest becomes HardwareLookupStandInTest, whose
stand-in for the cloud service answers what each test sets. Each case runs
for both examples.

- Without profiles. The accessible properties have no hardware element.
  The test now compares the whole line, and requires that nothing is
  logged as an error and no stack trace is printed, as well as exit code
  0, no lookup heading and no lookup request.
- No devices. The accessible properties carry the hardware element and
  each lookup answers with an empty list of profiles. Each heading must be
  followed by the line saying no devices are associated with the value.
- Properties fail every time. The accessible properties request answers
  500 with an error. The example must end with a non-zero exit code, with
  the cloud service's error logged as an error, no lookup heading, no line
  saying the key lacks the lookup and no lookup request.
- Properties fail once. The first accessible properties request answers
  500 and the next gives no hardware element. The example must ask again,
  print the line saying the key lacks the lookup with no heading, and end
  with exit code 0.

The log lines carry colour codes around their level, which are removed
before the output is checked. The two new fixtures come from answers the
staging cloud gave, with the accessible properties cut down to what the
examples use, and hold no key.

AGENTS.md now names the error the examples end with against the published
4.5.130 packages, and says what the examples print when a lookup matches
nothing or the property list cannot be fetched.
@jwrosewell
jwrosewell marked this pull request as ready for review November 23, 2026 20:46
@jwrosewell
jwrosewell merged commit 3f99e38 into rc Nov 23, 2026
8 checks passed
@jwrosewell
jwrosewell deleted the test/hardware-lookup-follow-up branch November 23, 2026 20:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant