spago icon indicating copy to clipboard operation
spago copied to clipboard

Add --offline flag

Open JordanMartinez opened this issue 3 years ago • 8 comments

Description of the change

Fixes #575

Checklist:

  • [x] Added the change to the "Unreleased" section of the changelog
  • [ ] Added some example of the new feature to the README
  • [x] Added a test for the contribution (if applicable)

P.S.: the above checks are not compulsory to get a change merged, so you may skip them. However, taking care of them will result in less work for the maintainers and will be much appreciated 😊

JordanMartinez avatar Jan 25 '22 20:01 JordanMartinez

I'm not really sure what should be added to the readme (if anything). It's more likely that Nix tools would update their readme to show how to use this command in their workflow.

JordanMartinez avatar Jan 25 '22 21:01 JordanMartinez

I think we could merge this already, but I'd first like that we figure out a good testing story for this, because if we can't properly test that the changes we introduce are going to continue working, then we are deemed to break them.

I don't have many ideas about this though - nix-shell doesn't seem to offer any switch to disable the network :thinking:

f-f avatar Jan 27 '22 15:01 f-f

So.... how should I make progress on this?

JordanMartinez avatar Feb 04 '22 23:02 JordanMartinez

Could you mock all network calls so they fail the test right away if called? You could use these mocked calls for the offline mode test only.

thomashoneyman avatar Feb 04 '22 23:02 thomashoneyman

Oh, it looks like we can call a process with unshare -r -n to prevent it from reaching the network (on linux at least. We can run the offline tests only on Linux, I'm fine with this)

So I'd say the next step on this is to fixup a test infrastructure that runs the tests for the offline feature in such wrapper

f-f avatar Feb 05 '22 10:02 f-f

Hmm... I should add a second test that verifies spago build fails when we drop the offline flag but still use unshare -r -n...

JordanMartinez avatar Feb 05 '22 14:02 JordanMartinez

Dropping the offline flag but still running unshare -r -n does not produce the expected failure. I wondered as much. AFAICT, spago build should always work so long as the dependencies are stored in the cache folder. I think the real issue is that running Spago in a Nix environment means the .cache folder doesn't contain these dependencies and so triggers the network call.

JordanMartinez avatar Feb 05 '22 14:02 JordanMartinez

@JordanMartinez I see. The location of both Dhall and Spago folders is dependent on the value of the XDG_CACHE_DIR environment variable. We could try to set that do a temp directory when running these tests, so that they would start from a clean slate?

f-f avatar Feb 06 '22 14:02 f-f